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;
    }
  • 相关阅读:
    Ubuntu20.04更换软件源
    使用kubeadm安装k8s1.19版本之系统基础环境配置&k8s集群初始化(二)
    k8s如何删除处于terminating状态的ns资源
    k8s如何强制删除pod&pv&pvc和ns&namespace方法
    C语言中的有符号数和无符号整形数转换
    互联网-架构演进
    结合redis使token失效
    有一种爱叫做放手
    js 读取上传的json文件内容
    使用spark-md5获取文件的MD5值
  • 原文地址:https://www.cnblogs.com/Draymonder/p/9760530.html
Copyright © 2011-2022 走看看