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 题意:一个人到一些地方送披萨,要求找到一条路径能够遍历每一个城市后返回出发点,并且路径距离最短.最后输出最短距离即可.注意:每一 ...
随机推荐
- Linux远程管理命令
关机\重启 shutdown 选项 时间 参数 -r 重启 例子: shutdown 1分钟后关机 shutdown now 立刻关机 shutdown –r now 立即重启 shutdown 20 ...
- hyper-v安装windows7
win7镜像下载地址 http://msdn.itellyou.cn/ 该网站都是微软系列的正规软件 非常好用 在hyper-v 虚拟机安装windows系统时,到百度搜索了几个iso 都不好用 到h ...
- SpringCloud之熔断器Hystrix及服务监控Dashboard
目的: 服务雪崩效应 服务熔断服务降级 Hystrix默认超时时间设置 Hystrix服务监控Dashboard 服务雪崩效应 雪崩效应就是一种不稳定的平衡状态也是加密算法的一种特征,它指明文 ...
- 【转载】ASP.NET网站选购阿里云服务器的时候,阿里云账号个人认证以及企业认证有何不同
在采购阿里云产品,如阿里云云服务器.阿里云短信包.阿里云数据库MySql以及Sqlserver.阿里云对象存储OSS等云产品的时候,如果账号未进行实名认证,很多时候会要求实名认证操作,在实名认证时可选 ...
- PHP 结合 Boostrap 结合 js 实现学生列表删除编辑以及搜索功能(完结)
这个自己的小项目要先告一段落了.可能还有许多bug.请见谅 删除学生功能 PHP: // 这里是通过前端代码HTML中的 url 传过来的,用 $_GET 来获取(相关HTML代码可以看一下到主页看一 ...
- 智表(ZCELL)插件产品选型说明书,市场主流插件对比,帮您选型
智表(ZCELL)插件产品选型说明书,市场主流插件对比,帮您选型. 说明书下载:地址 一. 我们为什么需要智表插件产品 客户早已养成EXCEL中的操作习惯,BS架构下,普通的网页交互,与客户习惯 ...
- [SOLVED] “Error 1067: The process terminated unexpectedly” on Windows 10, 7 & 8
Windows background services enable Windows features function properly. If some errors happen to serv ...
- android 给ImageView设置路径
ImageView是Android程序中经常用到的组件,它将一个图片显示到屏幕上. 在UI xml定义一个ImageView如下: public void onCreate(Bundle savedI ...
- Swift枚举的全用法
鉴于昨天开会部门会议讨论的时候,发现有些朋友对枚举的用法还是存在一些疑问,所以就写下这个文章,介绍下Swift下的枚举的用法. 基本的枚举类型 来,二话不说,我们先贴一个最基本的枚举: enum Mo ...
- Winmanager,NERDTree和MiniBufExplorer
NERDTree树形浏览文件 MiniBufExplorer多文件同时编辑 Winmanager将NERDTree和MiniBufExplorer界面整合 下载 http://www.vim.org/ ...