你发现 pizza 种类数不会很多,状压一下就可以了

code:

  1. #include <bits/stdc++.h>
  2. #define M 11
  3. #define N 100005
  4. #define LL long long
  5. using namespace std;
  6. int n,m,cnt;
  7. int v[1<<M],tmp[M],id[1<<M],a1[1<<M],a2[1<<M];
  8. LL val[1<<M];
  9. LL mer[1<<M];
  10. int tot[1<<M];
  11. struct node
  12. {
  13. LL x;
  14. int id;
  15. node(LL x=0,int id=0):x(x),id(id){}
  16. };
  17. vector<node>gg[1<<M];
  18. bool cmp(node a,node b)
  19. {
  20. return a.x<b.x;
  21. }
  22. int main()
  23. {
  24. int i,j;
  25. scanf("%d%d",&n,&m);
  26. for(i=0;i<=10;++i) tmp[i]=1<<i;
  27. for(i=1;i<=n;++i)
  28. {
  29. int t,x,re=0;
  30. scanf("%d",&t);
  31. for(j=1;j<=t;++j) scanf("%d",&x),re|=tmp[x];
  32. ++v[re];
  33. }
  34. for(i=1;i<=m;++i)
  35. {
  36. LL x;
  37. scanf("%lld",&x);
  38. int t,o,re=0;
  39. scanf("%d",&t);
  40. for(j=1;j<=t;++j) scanf("%d",&o),re|=tmp[o];
  41. if(!val[re]||val[re]>x) val[re]=x, id[re]=i;
  42. gg[re].push_back(node(x,i));
  43. }
  44. for(i=1;i<tmp[10];++i) sort(gg[i].begin(),gg[i].end(),cmp);
  45. for(i=1;i<tmp[10];++i)
  46. {
  47. if(!val[i]) continue;
  48. if(gg[i].size()>=2)
  49. {
  50. if(!mer[i]||mer[i]>gg[i][0].x+gg[i][1].x)
  51. mer[i]=gg[i][0].x+gg[i][1].x,a1[i]=gg[i][0].id, a2[i]=gg[i][1].id;
  52. }
  53. for(j=i+1;j<=tmp[10];++j)
  54. {
  55. if(!val[j]) continue;
  56. if(!mer[i|j]||(mer[i|j]>val[i]+val[j]))
  57. {
  58. mer[i|j]=val[i]+val[j];
  59. a1[i|j]=id[i];
  60. a2[i|j]=id[j];
  61. }
  62. }
  63. }
  64. int mx=0;
  65. for(i=1;i<=tmp[10];++i)
  66. {
  67. if(!mer[i]) continue;
  68. tot[i]=0; // 枚举结合完的
  69. for(j=1;j<=tmp[10];++j) { if((i&j)==j) tot[i]+=v[j]; }
  70. if(!mx||(tot[i]>tot[mx])||(tot[i]==tot[mx]&&mer[i]<mer[mx])) mx=i;
  71. }
  72. // printf("%lld %d\n",mer[mx],tot[mx]);
  73. printf("%d %d\n",a1[mx],a2[mx]);
  74. return 0;
  75. }

  

CF1185F Two Pizzas 状压的更多相关文章

  1. CF1185F Two Pizzas

    CF1185F Two Pizzas 洛谷评测传送门 题目描述 A company of nn friends wants to order exactly two pizzas. It is kno ...

  2. TZOJ 2289 Help Bob(状压DP)

    描述 Bob loves Pizza but is always out of money. One day he reads in the newspapers that his favorite ...

  3. NOJ 1116 哈罗哈的大披萨 【淡蓝】 [状压dp+各种优化]

    我只能说,珍爱生命,远离卡常数的题...感谢陈老师和蔡神,没有他们,,,我调一个星期都弄不出来,,,, 哈罗哈的大披萨 [淡蓝] 时间限制(普通/Java) : 1000 MS/ 3000 MS   ...

  4. POJ3311 Hie with the Pie 【状压dp/TSP问题】

    题目链接:http://poj.org/problem?id=3311 Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total ...

  5. <状压DP>solution-POJ3311_Hie with the Pie

    Hie with the Pie Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers ...

  6. BZOJ 1087: [SCOI2005]互不侵犯King [状压DP]

    1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3336  Solved: 1936[Submit][ ...

  7. 【BZOJ-4197】寿司晚宴 状压DP

    4197: [Noi2015]寿司晚宴 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 694  Solved: 440[Submit][Status] ...

  8. nefu1109 游戏争霸赛(状压dp)

    题目链接:http://acm.nefu.edu.cn/JudgeOnline/problemShow.php?problem_id=1109 //我们校赛的一个题,状压dp,还在的人用1表示,被淘汰 ...

  9. poj3311 TSP经典状压dp(Traveling Saleman Problem)

    题目链接:http://poj.org/problem?id=3311 题意:一个人到一些地方送披萨,要求找到一条路径能够遍历每一个城市后返回出发点,并且路径距离最短.最后输出最短距离即可.注意:每一 ...

随机推荐

  1. 【flask】登陆后返回之前重定向跳转的页面

    登陆后返回之前重定向跳转的页面 一.前言 实现强制跳转到登陆页面,登陆后返回之前的页面的功能.网上跳登陆页面的很多:返回之前页面功能没多少.这里我只是用了自己的方法,有缺点和其他方法也请指点!(´ε` ...

  2. Python知识点图片

  3. JSVC安装

    执行./start-all.sh启动hadoop时报错 Starting datanodes node1: ERROR: Cannot set priority of datanode process ...

  4. IdentityServer4实现Oauth2.0四种模式之隐藏模式

      接上一篇:IdentityServer4实现OAuth2.0四种模式之密码模式,密码模式将用户的密码暴露给了客户端,这无疑是不安全的,隐藏模式可以解决这个问题,由用户自己在IdentityServ ...

  5. ubuntu classicmenu-indicator

      sudo add-apt-repository ppa:diesch/testing sudo apt-get update sudo apt-get install classicmenu-in ...

  6. js 页面技巧

    需要获取页面上固定的某个按钮的属性值.我们需要在页面加载完的第一刻将值存储到定义的变量,防止用户更改页面样式读不出当前元素.如果页面刷新会重置当前属性 <body> <input v ...

  7. HTML学习摘要4

    DAY 4 text-align 属性规定了元素中文本的水平对齐方式: <html> <body> <h1 style="text-align:center&q ...

  8. angular解决跨域问题

    通过angular自身的代理转发功能 配置package.json  启动项目通过npm start启动,会自动启动代理服务npm start

  9. Java 之 web 相关概念

    一.软件架构 1.C/S:客户端/服务器端 2.B/S:浏览器/服务器端(目前常用) 二.网络资源 1.静态资源 静态资源:所有用户访问后,得到的结果都是一样的,称为静态资源,静态资源可以直接被浏览器 ...

  10. Qt ListWidget item 发起拖放

    第一步:重写类 MyListWidget 继承自 QListWidget 第二步:重写 mousePressEvent 函数 和 mouseMoveEvent 函数 void mousePressEv ...