zoukankan      html  css  js  c++  java
  • 状态压缩 HDU1074

    t组数据

    n门课程 底限 完成要几天

    dp[i] 表示i的二进制数中  1 对应位置课程 完成  最少扣多少分 完成的时间 记录一下怎么下来的

    1->2^n 列举

    (1<<n)   -1 就是全部都是1  然后输出即可

    #include<stdio.h>
    #include<algorithm>
    #include<string.h>
    #include<stack>
    
    using namespace std;
    
    #define inf 100000000
    
    struct node
    {
        char z[100];
        int da,ta;
    
    }x[20];
    struct node1
    {
        int time,pa,sc,now;
    
    }dp[1<<16];
    
    bool cmp(node a,node b)
    {
        return strcmp(a.z,b.z)<0;
    }
    stack<int>s;
    
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            int n;
            scanf("%d",&n);
            for(int i=0;i<n;i++)
                scanf("%s%d%d",x[i].z,&x[i].da,&x[i].ta);
            sort(x,x+n,cmp);
            int en=1<<n;
    
            for(int i=1;i<=en;i++)
            {
                dp[i].sc=inf;
                for(int j=n-1;j>=0;j--)
                {
                    int tem=1<<j;
                    if(i&tem)
                    {
                        int past=i-tem;
                        int st=dp[past].time+x[j].ta-x[j].da;
                        if(st<0)
                            st=0;
                        if(st+dp[past].sc<dp[i].sc)
                        {
                            dp[i].sc=st+dp[past].sc;
                            dp[i].pa=past;
                            dp[i].now=j;
                            dp[i].time=dp[past].time+x[j].ta;
                        }
                    }
                }
            }
    
            en--;
            printf("%d
    ",dp[en].sc);
            while(en)
            {
                s.push(dp[en].now);
                en=dp[en].pa;
            }
            while(!s.empty())
            {
                int now=s.top();
                printf("%s
    ",x[now].z);
                s.pop();
            }
        }
    
        return 0;
    }
  • 相关阅读:
    图像梯度计算
    图像轮廓检测
    元组()
    SwiftUI 概览
    TCL 语言概览
    列表 []
    Numpy 矩阵计算
    图像平滑(滤波)
    language="JavaScript"与type="text/javascript"
    调用接口, Test.java(不用任何包, MD5大写32位加密,HttpURLConnection)
  • 原文地址:https://www.cnblogs.com/cherryMJY/p/6125256.html
Copyright © 2011-2022 走看看