记录编号 332920 评测结果 AAAAAAAA
题目名称 王伯买鱼 最终得分 100
用户昵称 GravatarHzoi_Go灬Fire 是否通过 通过
代码语言 C++ 运行时间 0.019 s
提交时间 2016-10-29 14:25:36 内存使用 0.34 MiB
显示代码纯文本
  1. /*
  2. Name: 王伯买鱼
  3. Copyright:
  4. From:cogs
  5. Author: Go灬Fire
  6. Date: 29/10/16 14:26
  7. Description:当初考试完挂,现在虐它如虐傻瓜
  8. */
  9. #include<cstring>
  10. #include<algorithm>
  11. #include<cstdio>
  12. #include<cmath>
  13. #include<iostream>
  14. using namespace std;
  15. const int maxn=1010;
  16. struct Edge{
  17. int next,to,from;
  18. }e[maxn];
  19. int len,head[maxn],tot,n,v[maxn],ansnum,anstot;
  20. bool us[maxn],ans[maxn];
  21. int vis[maxn];
  22. void Insert(int x,int y){
  23. len++;e[len].to=y;e[len].next=head[x];e[len].from=x;head[x]=len;
  24. }
  25. void Init();
  26. void Dfs(int x,int num,int cost){
  27. if(cost>tot || n-x+1+num<ansnum)return;//小小的剪枝优化
  28. if(x==n+1){
  29. if(num>ansnum){
  30. ansnum=num;anstot=cost;
  31. for(int j=1;j<=n;j++)ans[j]=us[j];
  32. }
  33. else if(num==ansnum && cost>anstot){
  34. anstot=cost;
  35. for(int j=1;j<=n;j++)ans[j]=us[j];
  36. }
  37. else if(num==ansnum && cost==anstot)for(int j=1;j<=n;j++)ans[j]=us[j];//如果有评测插件此句不需要
  38. return;
  39. }
  40. if(vis[x])Dfs(x+1,num,cost);
  41. else {
  42. Dfs(x+1,num,cost);
  43. vis[x]++;us[x]=1;
  44. for(int i=head[x];i;i=e[i].next){
  45. int j=e[i].to;
  46. vis[j]++;
  47. }
  48. Dfs(x+1,num+1,cost+v[x]);
  49. vis[x]--;us[x]=0;
  50. for(int i=head[x];i;i=e[i].next){
  51. int j=e[i].to;vis[j]--;
  52. }
  53. }
  54. }
  55. int main(){
  56. freopen("fish.in","r",stdin);freopen("fish.out","w",stdout);
  57. Init();
  58. //for(;;);
  59. getchar();getchar();
  60. return 0;
  61. }
  62. void Init(){
  63. scanf("%d%d",&tot,&n);
  64. for(int i=1;i<=n;i++){
  65. int x,y;scanf("%d%d",&x,&y);
  66. v[x]=y;
  67. }
  68. int x,y;
  69. while(scanf("%d%d",&x,&y) && x!=0 && y!=0)Insert(x,y),Insert(y,x);
  70. Dfs(1,0,0);
  71. printf("%d %d\n",ansnum,anstot);
  72. for(int i=1;i<=n;i++)if(ans[i])printf("%d\n",i);
  73. }