Codeforces Gym 100676G Training Camp-like pressure DP

Source: Internet
Author: User

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&LT;&LT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.