The n-point homework is given. Each homework has a cutoff time and the number of days required. If a homework has exceeded the deadline for one day, one cent will be fined. How can I arrange do homework to minimize the penalty?
Idea: the first State compression DP is also very tangled... this time I discussed it with Wen Dong and Xin Gu, and I understood it more.
Because there are 15 homework copies in total, there are 15! But if you use the 2-in-progress dp, the status of 2 ^ 15 is acceptable.
This is the so-called State compression DP, which is to use the 0 auxiliary state to derive the large number from the decimal number, so as to achieve State transfer:
The current status is obtained from the previous status, because the penalty score can be updated.
It feels like a violent dp.
Here the binary system is used very well, because the subsequent State is introduced according to the previous state, which is similar to the increasing of the binary system.
AC Program: (no comments)
# Include <iostream> # include <stdio. h> # include <stdlib. h> # include <math. h> # include <algorithm> # include <string. h >#include <map> # define inf 35000 # define oo 1000000000 using namespace std; struct node {string name; int fday; int lday;} hw [20]; struct point {int pre; // prefix int rescore; // penalty int ttime; // current time point () {pre =-1; rescore = oo; // calculate the minimum value and assign the value ttime = 0 ;}}; void pn (int state, point dp []) {if (state = 0) return; in T pre2 = dp [state]. pre; pn (pre2, dp); int work = (state ^ pre2), cnt = 0; while (work! = 1) {work = (work> 1); cnt ++;} cout
AC Program (comments ):
# Include <iostream> # include <stdio. h> # include <stdlib. h> # include <math. h> # include <algorithm> # include <string. h >#include <map> # define inf 35000 # define oo 1000000000 using namespace std; struct node {string name; int fday; int lday;} hw [20]; struct point {int pre; // prefix int rescore; // int ttime for penalty; // current time point () {pre =-1; rescore = oo; // calculate the minimum value and assign the value ttime = 0 ;}}; void pn (int state, point dp []) {if (state = 0) // 0 is the auxiliary state, and Is the start status return; int pre2 = dp [state]. pre; pn (pre2, dp); int work = (state ^ pre2), cnt = 0; while (work! = 1) {work = (work> 1); cnt ++;} cout