HDU 1074 Doing Homework

Source: Internet
Author: User
Tags date1

Test instructions: Input T indicates the number of samples, input n means there are n accounts, n rows are entered, each line has name,endtime,costtime. A deduction of more than Endtime, the minimum number of points to be deducted.

Analysis: Compressed state, each state may be converted from a number of States, to find the least deduction, update the current status of the value.

#include <iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<queue>using namespacestd;structsubject{Charname[111]; intEnd, cost;} s[1<< -];structdp{intCost ; intreduced; intPre;} dp[1<< -];intvisit[1<< -];voidPrintintdate) {    if(Date = =0)    {        return ; }    intwhich; Which= date^Dp[date].pre; intNumber=0;  while(which) {which>>=1; number++;    } print (Dp[date].pre); printf ("%s\n", s[number-1]. Name);}intMain () {intT, N; scanf ("%d", &t);  while(t--) {scanf ("%d", &N);  for(intI=0; i<n; i++) {scanf ("%s%d%d", S[i]. Name, &s[i]. End, &S[i].        Cost); }        intE = (1<<n)-1; dp[0].cost=0; dp[0].pre=-1; dp[0].reduced =0; visit[0] =1; memset (Visit,0,sizeof(visit));  for(intI=0; i<e; i++)        {             for(intj=0; j<n; J + +)            {                intDate1 =1<<J; if((i&date1) = =0)//This assignment has not been done {intDate2 = i|date1; Dp[date2].cost= Dp[i].cost +S[j].                    cost; intreduce = dp[date2].cost-S[j].                    End; if(reduce<0) Reduce=0; Reduce+=dp[i].reduced; if(Visit[date2])//Previous state existed {if(reduce<dp[date2].reduced) {dp[date2].reduced=reduce; Dp[date2].pre=i; }                    }                    Else{Visit[date2]=1; dp[date2].reduced=reduce; Dp[date2].pre=i; } }}} printf ("%d\n", dp[e].reduced);    Print (e); }    return 0;}

HDU 1074 Doing Homework

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.