记录编号 |
346966 |
评测结果 |
AAAAAAAA |
题目名称 |
王伯买鱼 |
最终得分 |
100 |
用户昵称 |
AntiLeaf |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.053 s |
提交时间 |
2016-11-12 17:43:44 |
内存使用 |
0.31 MiB |
显示代码纯文本
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- #include<vector>
- using namespace std;
- const int maxn=35;
- void dfs(int,int,int);
- int n,m,x,y,w[maxn],ans=0,tmp=0;
- bool G[maxn][maxn]={{false}};
- vector<int>a,b;
- int main(){
- #define MINE
- #ifdef MINE
- freopen("fish.in","r",stdin);
- freopen("fish.out","w",stdout);
- #endif
- scanf("%d%d",&m,&n);
- for(int i=1;i<=n;i++){
- scanf("%d",&x);
- scanf("%d",&w[x]);
- }
- while(scanf("%d%d",&x,&y)==2&&x&&y)G[x][y]=G[y][x]=true;
- dfs(1,0,0);
- printf("%d %d\n",ans,tmp);
- for(int i=0;i<ans;i++)printf("%d\n",b[i]);
- #ifndef MINE
- printf("\n-------------------------DONE-------------------------\n");
- for(;;);
- #endif
- return 0;
- }
- void dfs(int x,int cnt,int cost){
- if(cost>m)return;
- if(x>n){
- if(cnt>ans){
- ans=cnt;
- tmp=cost;
- b=a;
- }
- else if(cnt==ans&&cost>tmp){
- tmp=cost;
- b=a;
- }
- return;
- }
- if(n-x+cnt+1<ans)return;
- bool ok=true;
- for(int i=0;i<cnt;i++)if(G[a[i]][x]){ok=false;break;}
- if(ok){
- a.push_back(x);
- dfs(x+1,cnt+1,cost+w[x]);
- a.pop_back();
- }
- dfs(x+1,cnt,cost);
- }