记录编号 |
119589 |
评测结果 |
AAAAAAAA |
题目名称 |
王伯买鱼 |
最终得分 |
100 |
用户昵称 |
HouJikan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.360 s |
提交时间 |
2014-09-13 10:34:21 |
内存使用 |
0.27 MiB |
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint;
const int INF=0x7ffffff;
//==============struct declaration==============
struct fishs
{
int no;int cost;
bool operator <(const fishs &rhs) const
{
return cost<rhs.cost;
}
}fish[40];
//==============var declaration=================
vector <int> unable[31];
bool chosen[31],maxchosen[31];
int maxfish=0,maxcost=0,money,n;
//==============function declaration============
void dfs(int pos,int cost,int cnt);
//==============main code=======================
int main()
{
string FileName="fish";//程序名
string FloderName="COGS";//文件夹名
freopen((FileName+".in").c_str(),"r",stdin);
freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG
system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
clock_t Start_Time=clock();
#endif
scanf("%d%d",&money,&n);
For(i,1,n)
{
int no,c;
scanf("%d%d",&no,&c);
fish[i].no=no;fish[i].cost=c;
}
stable_sort(fish+1,fish+1+n);
int s,e;
memset(chosen,false,sizeof(chosen));
while (scanf("%d%d",&s,&e)&&s&&e)
unable[s].push_back(e),unable[e].push_back(s);
dfs(1,0,0);
pritnf("%d %d\n",maxfish,maxcost);
For(i,1,n)
if (maxchosen[i])
pritnf("%d\n",i);
#ifdef DEBUG
clock_t End_Time=clock();
pritnf("\n\nTime Used: %.6lf",double(End_Time-Start_Time)/CLOCKS_PER_SEC);
#endif
return 0;
}
//================fuction code====================
void dfs(int pos,int costs,int cnt)
{
if (costs>money) return;
if (cnt>maxfish||(cnt==maxfish&&costs>=maxcost))
{
maxfish=cnt;
maxcost=costs;
memcpy(maxchosen,chosen,sizeof(maxchosen));
}
if (pos!=n+1)
{
bool suc=true;
int siz=unable[fish[pos].no].size()-1;
For(i,0,siz)
if (chosen[unable[fish[pos].no][i]])
{
suc=false;
break;
}
if (suc)
{
chosen[fish[pos].no]=true;
dfs(pos+1,costs+fish[pos].cost,cnt+1);
chosen[fish[pos].no]=false;
}
dfs(pos+1,costs,cnt);
}
}