HDU1074 Doing Homework

Source: Internet
Author: User

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 

 

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.