zoukankan      html  css  js  c++  java
  • hdu 1074 Doing Homework

    Doing Homework

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 12397    Accepted Submission(s): 5976


    Problem Description
    Ignatius has just come back school from the 30th ACM/ICPC. Now he has 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 will reduce his score of the final test, 1 day for 1 point. And as you know, doing homework always takes a long time. So Ignatius wants you 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 is a single integer T which is the number of test cases. T test cases follow.
    Each test case 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 will at most has 100 characters) and two integers D(the deadline of the subject), C(how many days will it take Ignatius to finish this subject's homework). 

    Note: All the subject names are given in the alphabet increasing order. So you 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, one subject in a line. If there are more than one orders, you should output the alphabet smallest one.
     
     
     
     用time[i] 来表示i的二进制位为1的作业所构成的集合完作业所需要 的时间
     用dp[i] 来表示i的二进制位为1的作业所构成的集合完作业所扣的最少分数
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <string.h>
    #include <string>
    #include <stack>
    using namespace std;
    
    const int N = (1<<15)+10;
    
    int n, ddl[20], ti[20];
    string str[20];
    int dp[N], tim[N], pre[N], now[N];
    
    int main()
    {
        //freopen("in","r",stdin);
        int T; scanf("%d",&T);
        while(T--) {
            scanf("%d", &n);
            for(int i=0;i<n;i++) {
                cin >> str[i];
                scanf("%d %d", &ddl[i], &ti[i]);
            }
            memset(dp,0x3f,sizeof(dp));
            memset(tim,0,sizeof(tim));
            memset(pre,0,sizeof(pre));
            memset(now,0,sizeof(now));
            int end = (1<<n);
            dp[0] = 0;
            for(int s=1; s<end; s++) {
                for(int i=0; i<n; i++) {
                    if((s>>i)&1) {
                        int preState = s - (1<<i);
                        int ans = max(0, tim[preState] + ti[i] - ddl[i]);
                        if(dp[preState] + ans <=  dp[s]) {
                            dp[s] = dp[preState] + ans;
                            tim[s] = tim[preState] + ti[i];
                            now[s] = i;
                            pre[s] = preState;
                        } 
                    }    
                }
            }
            stack<int> st;
            int ed = (1<<n)-1;
            while (ed != 0) {
                st.push(now[ed]);
                ed = pre[ed];
            }
            cout << dp[end-1] <<endl;
            while (!st.empty()) {
                cout << str[st.top()]<<endl;
                st.pop();
            }
        }
        return 0;
    }
  • 相关阅读:
    ArcGis面要素空间连接,取相交面积最大者 C#
    迅雷下载器无限制版_无敏感_无限速
    redhat 6.8 配置 centos6 163 的 yum 源
    apache cgi 程序: End of script output before headers
    centos php 安装 decrypt
    url传输中+转为%2B取到变空格的问题
    快速搭建自己的搜索引擎
    ffmpeg 文件推流 rtsp和rtmp
    svn 服务器操作
    edusoho迁移
  • 原文地址:https://www.cnblogs.com/Draymonder/p/9760530.html
Copyright © 2011-2022 走看看