http://codeforces.com/gym/100676
The main idea is to tell you to fix n courses, each course has a weight of w[i], in the K-day course to get k*w[i] of the learning points, give the curriculum and the relationship between the first course, to take the course must be completed prior to the course. Ask how many points you can learn.
A very simple pressure DP (I also misled my teammates to write a two-dimensional t^t);
Dp[s]: s binary is the maximum number of points that can be obtained in the selected course, in that state.
If you learn another course k, you will be transferred to the state SS (s | (1 << k)) , can transfer need to judge legitimacy. Here the course K's first course exists in an int, S & prev[k] = = Prev[k], which indicates the option K course. The DP array initially needs to be initialized to infinity. Finally just look for dp[(1 << N)-1].
/* Input really disgusting */
#include <map>#include<cstdio>#include<vector>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;Const intINF =999999999;intN,m;map<string,int>Map;intw[ -];intprve[ -];voidRead () {cin>> N >>M;getchar (); Char_a[101]; string_s, _t; int_num; int_len; for(intI=0; i<n; i++) {gets (_a); _len=strlen (_a); intK =0; while(_a[k] <'0'|| _A[K] >'9') k++; _a[k-1] =' /'; _s= (string) _a; _num=0; while(K < _len && _a[k] >='0'&& _a[k] <='9') {_num= _num *Ten+ _a[k]-'0'; K++; } map[_s]=i; W[i]=_num; } for(intI=0; i<m; i++) {gets (_a); intK =0; while(_a[k]! ='-') k++; _a[k-1] =' /'; _s= (string) _a; _t= (string) (_a + k +4); PRVE[MAP[_T]]|= (1<<map[_s]); }}intdp[(1<< -)+5];voidDP () { for(ints=0; s< (1<<N); s++) { int_num =0; for(intI=0; i<n; i++) {_num+ = ((s >> i) &1); } for(intI=0; i<n; i++) { intSS = S | (1<<i); if((S >> I &1) !=0) || ((S & prve[i]) = Prve[i]))Continue; if(_num = =0&& Prve[i] = =0) {DP[SS]=W[i]; Continue; } Dp[ss]= Max (Dp[ss], Dp[s] + (_num +1) *W[i]); }} cout<< dp[(1<<n)-1] <<Endl;}voidinit () {map.clear (); Fill (DP, DP+ (1<< -), -INF); memset (Prve,0,sizeof(Prve));}intMain () {intT; CIN>>T; while(t--) {init (); Read (); DP (); } return 0;}
View Code
Codeforces Gym 100676G Training Camp-like pressure DP