ACM-ICPC 2018 南京賽區網路預賽__E AC Challenge【狀態壓縮+DP】
- 1000ms
- 128536K
Dlsj is competing in a contest with n(0<n≤20) problems. And he knows the answer of all of these problems.
However, he can submit i-th problem if and only if he has submitted (and passed, of course) si problems, the pi,1-th,pi,2-th, ......, pi,si-th problem before.(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 i), he can get t×ai+bi points. (∣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, n, which is the number of problems.
Then follows n lines, the i-th line contains si+3 integers, ai,bi,si,p1,p2,...,psi as 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×5+6=11 points.
On the second minute, Dlsj submitted the second problem, and get 2×4+5=13 points.
On the third minute, Dlsj submitted the third problem, and get 3×3+4=13 points.
On the forth minute, Dlsj submitted the forth problem, and get 4×2+3=11 points.
On the fifth minute, Dlsj submitted the fifth problem, and get 5×1+2=7 points.
So he can get 11+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
樣例輸入
1
-100 0 0
樣例輸出2
0
題目來源
題目大意:給n個問題,然後每個問題 給出a,b,s 分別表示 第i個解決這個題,就給 (a*i+b) 的得分,s表示有 s個前置問題,必須回答出來 s個前置問題 才能解決這個問題,求最大的得分,注意,可以不用答完所有的題
題解:狀態壓縮+DP。AC的C++程式碼:
#include<iostream>
using namespace std;
typedef long long ll;
const ll INF=1e18;
const int N=21;
struct Problem{
ll a,b;
int pre;
}p[N];
ll dp[1<<N];
int main()
{
int n,s,x;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%lld%lld%d",&p[i].a,&p[i].b,&s);
p[i].pre=0;
while(s--){
scanf("%d",&x);
p[i].pre|=(1<<(x-1));
}
}
for(int i=0;i<(1<<n);i++)//將所有狀態置為-INF
dp[i]=-INF;
dp[0]=0;
ll res=0;
for(int i=0;i<(1<<n);i++){//遍歷所有狀態
if(dp[i]==-INF)//如果這個狀態無法由初始狀態得來就跳過
continue;
//解題順序t等於已經解決的題數加一
int t=1;
//統計現在已經解決的題數,二進位為1的個數
for(int j=0;j<n;j++)
if(i&(1<<j))
t++;
for(int j=0;j<n;j++){
if(i&(1<<j)) continue;//如果第j到題已經做過了就跳過
//如果第j道題還沒做,
//且要解決第j題所需先要解決的問題已經解決,就進行更新
if((p[j].pre&i)==p[j].pre){
int tmp=i|(1<<j);//解決第j道題後的狀態
ll val=dp[i]+t*p[j].a+p[j].b;//解決第j道題後的總分
dp[tmp]=max(dp[tmp],val);
res=max(res,dp[tmp]);
}
}
}
printf("%lld\n",res);
return 0;
}
相關文章
- ACM-ICPC 2018 南京賽區網路預賽__K The Great Nim Game【博弈論+費馬小定理+DP】ACMGAM
- ACM-ICPC 2018 南京賽區網路預賽__B The writing on the wall【列舉】ACM
- ACM-ICPC 2018 徐州賽區網路預賽ACM
- ACM-ICPC 2018 瀋陽賽區網路預賽ACM
- ACM-ICPC 2018 南京賽區網路預賽__J. Sum【尤拉篩法+質因子分解+思維】ACM
- ACM-ICPC 2018 徐州賽區網路預賽 F. Features TrackACM
- ACM-ICPC 2018 南京賽區網路預賽 __G Lpl and Energy-saving Lamps【線段樹+模擬】ACMLAMP
- ACM-ICPC 2018 南京賽區網路預賽__L. Magical Girl Haze 【Dijkstra演算法+分層圖思想】ACM演算法
- ACM-ICPC 2018 徐州賽區網路預賽 I. Characters with Hash【簽到題】ACM
- 2014上海網路賽1004||hdu5045 contest【狀態壓縮dp】
- 2014上海網路賽1004||hdu5045 二分圖的最佳匹配 或 狀態壓縮dp
- 2018icpc 南京網路賽L Magical Girl Haze
- HDU4592 Boring Game (2013 ACM-ICPC南京賽區全國邀請賽) 高斯消元GAMACM
- 演算法學習之路|狀態壓縮dp演算法
- 2014鞍山網路賽 E題||hdu 5001 概率dp
- NOIP2005過河[DP 狀態壓縮]
- 2018 瀋陽賽區網路預賽 I.Lattice's basics in digital electronics(模擬)Git
- 2014廣州網路賽1002||hdu5023 線段樹&&狀態壓縮
- E - Remove Pairs(狀壓dp+博弈論)REMAI
- 2018 北京賽區網路預選賽 A. Saving Tang Monk II(BFS+優先佇列)佇列
- URAL 1152 False Mirrors(簡單的狀態壓縮dp)False
- 第43屆ACM-ICPC國際大學生程式設計競賽 亞洲區域賽南京站現場賽名額分配相關說明ACM程式設計
- 動態規劃——用二進位制表示集合的狀態壓縮DP動態規劃
- UVA 11825 dp、狀態壓縮、二進位制法表示集合
- 狀壓 dp
- 狀壓DP
- hdu3001 狀態壓縮dp+三進位制
- 沙漠or綠洲,從南京軟博會I.D.Spark網際網路創新大賽看南京網際網路發展Spark
- 論文閱讀 狀態壓縮
- 2018 徐州網路賽 G 題解
- 2018華為網路技術大賽
- 第三屆華中地區邀請賽網路賽題解
- Nginx網路壓縮 CSS壓縮 圖片壓縮 JSON壓縮NginxCSSJSON
- 為加快南京AI產業發展,2018全球(南京)人工智慧應用大賽現公開徵集賽題原型AI產業人工智慧原型
- 第二屆學習影象壓縮挑戰賽
- [Offer收割]程式設計練習賽1 hihocoder 1271 艦隊遊戲 (狀態壓縮+貪心 好題)程式設計遊戲
- POJ3279 Fliptile【狀態壓縮+DFS】
- 狀態壓縮動態規劃 -- 炮兵陣地動態規劃