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, ...
随机推荐
- python循环导入的解决方案
解决循环import的方法主要有几种: 1.延迟导入(lazy import) 即把import语句写在方法或函数里面,将它的作用域限制在局部. 这种方法的缺点就是会有性能问题. 2. ...
- 关于spring的bean
1 spring bean的单例和多例 singleton 单例指的是,在需要该bean的地方,spring framework返回的是同一个值. prototype 多例指的是,在需要该bean的地 ...
- what is spring and what is spring for
1 what is spring spring是一个轻量级的容器. 它使用依赖注入技术来构建耦合性很低的系统. 2 what is spring for 用于系统的依赖解耦合.在一个系统中,A类依赖 ...
- mysql系列之8.mysql高可用 (mha4mysql)
环境: 三台机器 主服务器: 192.168.1.130 主备机器: 192.168.1.131 监控机器: 192.168.1.132 130和131, 是mysql双主架构 1.在三台机器上安装m ...
- c#中多线程写DataGridView出现滚动栏导致程序卡死(无响应)的解决的方法
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u013529927/article/details/24225567 由于写的程序涉及到多线程维护一 ...
- Unix和Linux历史文化
1.显示工作目录pwd print working directory print name of current/working directory 2.显示自己终端名称tty pr ...
- Java for LeetCode 120 Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- Database: coursera assignment 1
q.1: Find the titles of all movies directed by Steven Spielberg. select title from moviewhere direct ...
- leetcode 859. Buddy Strings
Given two strings A and B of lowercase letters, return true if and only if we can swap two letters i ...
- [egret+pomelo]实时对战游戏杂记(5)
之前大体了解了pomelo服务端的运行的大体运行流程,下面详细的学习一下在服务端比较重要的一个容器模块bearcat,在bearcat的wiki中我们可以对其有个大概的了解,在服务端示例的代码中也大量 ...