CF1185F Two Pizzas 状压
你发现 pizza 种类数不会很多,状压一下就可以了
code:
- #include <bits/stdc++.h>
- #define M 11
- #define N 100005
- #define LL long long
- using namespace std;
- int n,m,cnt;
- int v[1<<M],tmp[M],id[1<<M],a1[1<<M],a2[1<<M];
- LL val[1<<M];
- LL mer[1<<M];
- int tot[1<<M];
- struct node
- {
- LL x;
- int id;
- node(LL x=0,int id=0):x(x),id(id){}
- };
- vector<node>gg[1<<M];
- bool cmp(node a,node b)
- {
- return a.x<b.x;
- }
- int main()
- {
- int i,j;
- scanf("%d%d",&n,&m);
- for(i=0;i<=10;++i) tmp[i]=1<<i;
- for(i=1;i<=n;++i)
- {
- int t,x,re=0;
- scanf("%d",&t);
- for(j=1;j<=t;++j) scanf("%d",&x),re|=tmp[x];
- ++v[re];
- }
- for(i=1;i<=m;++i)
- {
- LL x;
- scanf("%lld",&x);
- int t,o,re=0;
- scanf("%d",&t);
- for(j=1;j<=t;++j) scanf("%d",&o),re|=tmp[o];
- if(!val[re]||val[re]>x) val[re]=x, id[re]=i;
- gg[re].push_back(node(x,i));
- }
- for(i=1;i<tmp[10];++i) sort(gg[i].begin(),gg[i].end(),cmp);
- for(i=1;i<tmp[10];++i)
- {
- if(!val[i]) continue;
- if(gg[i].size()>=2)
- {
- if(!mer[i]||mer[i]>gg[i][0].x+gg[i][1].x)
- mer[i]=gg[i][0].x+gg[i][1].x,a1[i]=gg[i][0].id, a2[i]=gg[i][1].id;
- }
- for(j=i+1;j<=tmp[10];++j)
- {
- if(!val[j]) continue;
- if(!mer[i|j]||(mer[i|j]>val[i]+val[j]))
- {
- mer[i|j]=val[i]+val[j];
- a1[i|j]=id[i];
- a2[i|j]=id[j];
- }
- }
- }
- int mx=0;
- for(i=1;i<=tmp[10];++i)
- {
- if(!mer[i]) continue;
- tot[i]=0; // 枚举结合完的
- for(j=1;j<=tmp[10];++j) { if((i&j)==j) tot[i]+=v[j]; }
- if(!mx||(tot[i]>tot[mx])||(tot[i]==tot[mx]&&mer[i]<mer[mx])) mx=i;
- }
- // printf("%lld %d\n",mer[mx],tot[mx]);
- printf("%d %d\n",a1[mx],a2[mx]);
- return 0;
- }
CF1185F Two Pizzas 状压的更多相关文章
- CF1185F Two Pizzas
CF1185F Two Pizzas 洛谷评测传送门 题目描述 A company of nn friends wants to order exactly two pizzas. It is kno ...
- TZOJ 2289 Help Bob(状压DP)
描述 Bob loves Pizza but is always out of money. One day he reads in the newspapers that his favorite ...
- NOJ 1116 哈罗哈的大披萨 【淡蓝】 [状压dp+各种优化]
我只能说,珍爱生命,远离卡常数的题...感谢陈老师和蔡神,没有他们,,,我调一个星期都弄不出来,,,, 哈罗哈的大披萨 [淡蓝] 时间限制(普通/Java) : 1000 MS/ 3000 MS ...
- POJ3311 Hie with the Pie 【状压dp/TSP问题】
题目链接:http://poj.org/problem?id=3311 Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total ...
- <状压DP>solution-POJ3311_Hie with the Pie
Hie with the Pie Description The Pizazz Pizzeria prides itself in delivering pizzas to its customers ...
- BZOJ 1087: [SCOI2005]互不侵犯King [状压DP]
1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3336 Solved: 1936[Submit][ ...
- 【BZOJ-4197】寿司晚宴 状压DP
4197: [Noi2015]寿司晚宴 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 694 Solved: 440[Submit][Status] ...
- nefu1109 游戏争霸赛(状压dp)
题目链接:http://acm.nefu.edu.cn/JudgeOnline/problemShow.php?problem_id=1109 //我们校赛的一个题,状压dp,还在的人用1表示,被淘汰 ...
- poj3311 TSP经典状压dp(Traveling Saleman Problem)
题目链接:http://poj.org/problem?id=3311 题意:一个人到一些地方送披萨,要求找到一条路径能够遍历每一个城市后返回出发点,并且路径距离最短.最后输出最短距离即可.注意:每一 ...
随机推荐
- 【flask】登陆后返回之前重定向跳转的页面
登陆后返回之前重定向跳转的页面 一.前言 实现强制跳转到登陆页面,登陆后返回之前的页面的功能.网上跳登陆页面的很多:返回之前页面功能没多少.这里我只是用了自己的方法,有缺点和其他方法也请指点!(´ε` ...
- Python知识点图片
- JSVC安装
执行./start-all.sh启动hadoop时报错 Starting datanodes node1: ERROR: Cannot set priority of datanode process ...
- IdentityServer4实现Oauth2.0四种模式之隐藏模式
接上一篇:IdentityServer4实现OAuth2.0四种模式之密码模式,密码模式将用户的密码暴露给了客户端,这无疑是不安全的,隐藏模式可以解决这个问题,由用户自己在IdentityServ ...
- ubuntu classicmenu-indicator
sudo add-apt-repository ppa:diesch/testing sudo apt-get update sudo apt-get install classicmenu-in ...
- js 页面技巧
需要获取页面上固定的某个按钮的属性值.我们需要在页面加载完的第一刻将值存储到定义的变量,防止用户更改页面样式读不出当前元素.如果页面刷新会重置当前属性 <body> <input v ...
- HTML学习摘要4
DAY 4 text-align 属性规定了元素中文本的水平对齐方式: <html> <body> <h1 style="text-align:center&q ...
- angular解决跨域问题
通过angular自身的代理转发功能 配置package.json 启动项目通过npm start启动,会自动启动代理服务npm start
- Java 之 web 相关概念
一.软件架构 1.C/S:客户端/服务器端 2.B/S:浏览器/服务器端(目前常用) 二.网络资源 1.静态资源 静态资源:所有用户访问后,得到的结果都是一样的,称为静态资源,静态资源可以直接被浏览器 ...
- Qt ListWidget item 发起拖放
第一步:重写类 MyListWidget 继承自 QListWidget 第二步:重写 mousePressEvent 函数 和 mouseMoveEvent 函数 void mousePressEv ...