ACM-ICPC2018南京网络赛 AC Challenge(一维状压dp)
AC Challenge
- 30.04%
- 1000ms
- 128536K
Dlsj is competing in a contest with n (0 < n \le 20)n(0<n≤20) problems. And he knows the answer of all of these problems.
However, he can submit ii-th problem if and only if he has submitted (and passed, of course) s_isi problems, the p_{i, 1}pi,1-th, p_{i, 2}pi,2-th, ......, p_{i, s_i}pi,si-th problem before.(0 < p_{i, j} \le n,0 < j \le s_i,0 < i \le n)(0<pi,j≤n,0<j≤si,0<i≤n) After the submit of a problem, he has to wait for one minute, or cooling down time to submit another problem. As soon as the cooling down phase ended, he will submit his solution (and get "Accepted" of course) for the next problem he selected to solve or he will say that the contest is too easy and leave the arena.
"I wonder if I can leave the contest arena when the problems are too easy for me."
"No problem."
—— CCF NOI Problem set
If he submits and passes the ii-th problem on tt-th minute(or the tt-th problem he solve is problem ii), he can get t \times a_i + b_it×ai+bi points. (|a_i|, |b_i| \le 10^9)(∣ai∣,∣bi∣≤109).
Your task is to calculate the maximum number of points he can get in the contest.
Input
The first line of input contains an integer, nn, which is the number of problems.
Then follows nn lines, the ii-th line contains s_i + 3si+3 integers, a_i,b_i,s_i,p_1,p_2,...,p_{s_i}ai,bi,si,p1,p2,...,psias described in the description above.
Output
Output one line with one integer, the maximum number of points he can get in the contest.
Hint
In the first sample.
On the first minute, Dlsj submitted the first problem, and get 1 \times 5 + 6 = 111×5+6=11 points.
On the second minute, Dlsj submitted the second problem, and get 2 \times 4 + 5 = 132×4+5=13 points.
On the third minute, Dlsj submitted the third problem, and get 3 \times 3 + 4 = 133×3+4=13 points.
On the forth minute, Dlsj submitted the forth problem, and get 4 \times 2 + 3 = 114×2+3=11 points.
On the fifth minute, Dlsj submitted the fifth problem, and get 5 \times 1 + 2 = 75×1+2=7 points.
So he can get 11+13+13+11+7=5511+13+13+11+7=55 points in total.
In the second sample, you should note that he doesn't have to solve all the problems.
样例输入1复制
5
5 6 0
4 5 1 1
3 4 1 2
2 3 1 3
1 2 1 4
样例输出1复制
55
样例输入2复制
1
-100 0 0
样例输出2复制
0
题目来源
状压dp。
#include <bits/stdc++.h>
#define MAX 21
typedef long long ll;
using namespace std;
const int INF = 0x3f3f3f3f; ll a[MAX],b[MAX];
ll dp[<<];
vector<int> v[MAX]; int main(void)
{
int n,num,temp,i,j,k;
scanf("%d",&n);
for(i=;i<=n;i++) {
scanf("%lld %lld",&a[i],&b[i]);
scanf("%d",&num);
while(num--) {
scanf("%d",&temp);
v[i].push_back(temp);
}
}
memset(dp,,sizeof(dp));
for(i=;i<(<<n);i++){
int f=;
for(j=;j<=n;j++){
if(!((<<(j-))&i)) continue;
for(k=;k<v[j].size();k++){
if(!((<<(v[j][k]-))&i)){
f=;
break;
}
}
if(f==) break;
}
if(f==) continue;
for(j=;j<=n;j++){
if(!((<<(j-))&i)) continue;
int S=i;
int c=;
while(S){
if(S&) c++;
S>>=;
}
dp[i]=max(dp[i],dp[i^(<<(j-))]+c*a[j]+b[j]);
//printf("(%d %d %d %lld)",i,c,j,dp[i]);
}
}
printf("%lld\n",dp[(<<n)-]);
return ;
}
ACM-ICPC2018南京网络赛 AC Challenge(一维状压dp)的更多相关文章
- 南京网络赛E-AC Challenge【状压dp】
Dlsj is competing in a contest with n (0 < n \le 20)n(0<n≤20) problems. And he knows the answe ...
- AC Challenge(状压dp)
ACM-ICPC 2018 南京赛区网络预赛E: 题目链接https://www.jisuanke.com/contest/1555?view=challenges Dlsj is competing ...
- ACM-ICPC 2018 南京赛区网络预赛 E AC Challenge(状压dp)
https://nanti.jisuanke.com/t/30994 题意 给你n个题目,对于每个题目,在做这个题目之前,规定了必须先做哪几个题目,第t个做的题目i得分是t×ai+bi问最终的最大得分 ...
- 2019年第十届蓝桥杯省赛-糖果(一维状压dp)
看到20的数据量很容易想到状压dp. 开1<<20大小的数组来记录状态,枚举n个糖包,将其放入不同状态中(类似01背包思想) 时间复杂度O(n*(2^20)). import java.u ...
- HDU3247 Resource Archiver (AC自动机+spfa+状压DP)
Great! Your new software is almost finished! The only thing left to do is archiving all your n resou ...
- 2013 ACM/ICPC 南京网络赛F题
题意:给出一个4×4的点阵,连接相邻点可以构成一个九宫格,每个小格边长为1.从没有边的点阵开始,两人轮流向点阵中加边,如果加入的边构成了新的边长为1的小正方形,则加边的人得分.构成几个得几分,最终完成 ...
- HDU - 3247 Resource Archiver (AC自动机,状压dp)
\(\quad\)Great! Your new software is almost finished! The only thing left to do is archiving all you ...
- 【noip模拟赛5】细菌 状压dp
[noip模拟赛5]细菌 描述 近期,农场出现了D(1<=D<=15)种细菌.John要从他的 N(1<=N<=1,000)头奶牛中尽可能多地选些产奶.但是如果选中的奶牛携 ...
- HDU 3247 Resource Archiver (AC自动机+BFS+状压DP)
题意:给定 n 个文本串,m个病毒串,文本串重叠部分可以合并,但合并后不能含有病毒串,问所有文本串合并后最短多长. 析:先把所有的文本串和病毒都插入到AC自动机上,不过标记不一样,可以给病毒标记-1, ...
随机推荐
- C#操作XML方法:新增、修改和删除节点与属性
一 前言 先来了解下操作XML所涉及到的几个类及之间的关系 如果大家发现少写了一些常用的方法,麻烦在评论中指出,我一定会补上的!谢谢大家 * 1 XMLElement 主要是针对节点的一些属性进行操 ...
- nohup COMMAND > FILE
nohup --help nohup(1) - Linux man page https://linux.die.net/man/1/nohup
- Linux就该这么学--计划任务服务
有经验的系统运维工程师能够让系统自动化运行,无需人工的干预就可以让各个服务.命令在指定的时间段运行.停止. 计划任务分为: 一次性计划任务:今晚11:30开启网站服务 长期性计划任务:每周1.3.5的 ...
- SVN支干合并(转载)
分支用来维护独立的开发支线,在一些阶段,你可能需要将分支上的修改合并到最新版本,或者将最新版本的修改合并到分支. 此操作十分重要,在团队开发中,如果你是SVN 的维护者此环节可以说是必不可少,因为团队 ...
- Listfragment 列表标题 显示内容
activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout ...
- centos下安装nodejs及websocket
软件环境: VMware Workstation CentOS 6.5 NodeJS v0.12.5 安装过程: Step 1.确认服务器有nodejs编译及依赖相关软件,如果没有可通过运行以下命令安 ...
- linux中fflush函数和printf函数 【转】
本文转载自:http://blog.chinaunix.net/uid-30058258-id-5029847.html printf是一个行缓冲函数printf函数是标准函数,最终会调用到系统调用函 ...
- Vim设置括号自动补全和快速跳出
一.设置括号自动补全 inoremap ' ''<ESC>i inoremap " ""<ESC>i inoremap ( ()<ESC&g ...
- Android SDK Manager更新问题
1.如果是windows7,那么"开始-->所有程序-->Android SDK Tools-->右键SDK Manager-->以管理员身份运行(A)"2 ...
- 分享知识-快乐自己:Oracle中定义及使用同义词
Oracle 同义词概念: Oracle的同义词(synonyms)从字面上理解就是别名的意思,和视图的功能类似,就是一种映射关系. 它可以节省大量的数据库空间,对不同用户的操作同一张表没有多少差别; ...