HDUOJ1074 Doing Homework

Source: Internet
Author: User
Tags min printf time limit

Doing Homework

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 1693 Accepted Submission (s): 562
Problem Description Ignatius have just come back school from the 30th ACM/ICPC. Now he had a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the teacher would reduce his score of the final Test, 1 day for 1 poi Nt. And as you know, doing homework always takes a long time. So Ignatius wants-to-help him to arrange the order of doing homework to minimize the reduced score.

Input the input contains several test cases. The first line of the input was a single integer T which is the number of test cases. T test Cases follow.
Each test case is start with a positive integer N (1<=n<=15) which indicate the number of homework. Then N lines follow. Each line contains a string S (the subject's name, each string would at the most have characters) and a integers D (the dead Line of the subject), C (what many days would it take Ignatius to finish this subject ' s homework).

Note:all the subject names is given in the alphabet increasing order. So, may process the problem much easier.

Output for each test case, you should output the smallest total reduced score, then give out the order of the subjects, on e subject in a line. If there is more than one orders, you should output the alphabet smallest one.

Sample Input

2 3 Computer 3 3 中文版 1 Math 3 2 3 computer 3 3 中文版 6 3 Math 6 3

Sample Output

2 computer Math 中文版 3 computer English math "@@#¥" no, mean no idea, keep it later//1074.cpp: Defines the entry point for the console application. The typical permutation optimal problem,////DP[SA] indicates that the combined state is optimal for Sa,///Then dp[sa]=min{dp[sub]}+ (cost[sa]>d[r]?cost[sa]-d[r]:0); Where Cost[sa] represents the time spent in combination, regardless of the order of arrangement, pre-use DFS (01 backpack) ideas to find out//////#include "stdafx.h" #include <map> #include <set& Gt #include <list> #include <queue> #include <stack> #include <bitset> #include <vector> # Include <string> #include <algorithm> #include <iostream> #include <cstdio> #include < cstring> #include <cmath> #include <cstdlib> #include <iomanip> #include <cstdio> #include <iostream> #include <cstring> using namespace std; struct Node {int deadline,time; char name[103];} STU[17]; struct Info {int next;//successor, the output time is very convenient. int min_score; int day;} dp[1<<15]; int n; void Dfs (int k) {int i,j,id,kk,temp,count,score,time,min_time,next,min; char ch[16]; memset (CH, ' 0 ', sizeof (CH)); TEMP=k; i=14; count=0; The end of the 15th ch[15]=0;//. Equivalent to Plus/0, while (temp) {if (temp&1) {count++;//1), id=i;//record is 1 highest bit ch[i]= ' 1 ';} i--; temp=temp>>1;//left one bit.} if ( count==1)//Just complete a job {Id=14-id; if (stu[id].deadline>=stu[id].time) score=0; else Score=stu[id].time-stu[id]. Deadline Dp[k].min_score=score; Dp[k].day=stu[id].time; Dp[k].next=id; return; } min=99999999;//the optimal solution for finding the best dp[k]. for (i=15-n;i<15;i++) {if (ch[i]== ' 1 ') {id=14-i;//note here. kk=k-(1<<id);//Search Next, remove the highest ID of 1. if (dp[kk].min_ Score==-1) DFS (KK); Score=dp[kk].min_score; Time=dp[kk].day+stu[id].time; if (stu[id].deadline<time) score+= (time-stu[id].deadline);//Analog processing if (score<min| | (SCORE==TIME&AMP;&AMP;STRCMP (Stu[id].name,stu[next].name) <0)) {if (score<min) next=id; min=score; min_time=time;} }} dp[k].min_score=min; Dp[k].day=min_time; Dp[k].next=next; } int main () {int t; int u,i,j,k; int b[17],b_count; scanf ("%d/n", &t); for (u=0;u<t;u++) {scanf ("%d/n", &n); fo R (i=0;i<n;i++) {scanf ("%s%d%d/n", stu[i].name,&stu[i].deadline,&stu[i].time); } k= (1<<n)-1; for (i=0;i<=k;i++) {dp[i].min_score=-1;} dfs (k); printf ("%d/n", Dp[k].min_score); b_count=0; for (i=0;i<n;i++) {b[b_count++]=dp[k].next;//by subsequent traversal to get order, record subscript. k=k-(1<<dp[k].next);//successor} for (i=n-1;i>=0; i--) printf ("%s/n", stu[b[i]].name); } return 0; }

 

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.