hdu 1074 Doing Homework(dp+状态压缩)

本文探讨了一个学生如何在有限时间内合理安排作业,以最小化因延期提交而产生的分数扣减的问题。通过使用动态规划算法,学生能够根据每门课程的截止日期和完成时间,制定最优的作业完成顺序,从而降低最终考试成绩的扣分风险。

Doing Homework

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


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.

Sample Input
2 3 Computer 3 3 English 20 1 Math 3 2 3 Computer 3 3 English 6 3 Math 6 3

Sample Output
2 Computer Math English 3 Computer English Math
Hint
In the second test case, both Computer->English->Math and Computer->Math->English leads to reduce 3 points, but the word "English" appears earlier than the word "Math", so we choose the first order. That is so-called alphabet order.

Author
Ignatius.L
 
思路:

这题有作业数的规定,有每一样作业的截止时间要求,有写每一样作业所需花费的时间,作业要按期完成,否则每超一天扣一分,问怎样才能让他扣分最少。

原先我想和其他dp一样找状态转移方程,但感觉状态要表示出来很困难。由于题目说作业数最多是15,因此若我们采用一个2的15次方的数来表示,每一个数为0则表示尚未完成此项作业,为1则表示已完成此项作业,这样这个状态就很好表示了。

在这里设置一个结构体,里面要包含一个记录前驱的pre,然后自然的有最小的扣分代价,此外,由于是否在规定时间内完成了这道题目是由当前时间,截止时间和你花费时间共同决定的,那你就必须判断当前时间与截止时间的差距是多少,因此外设一个表示当前时间。

以dp[i]来表示完成了i这个二进制数中所有为1的位置的对应的作业的状态

至于递推条件:(1)对当前状态i进行枚举他所为0的部分,j,若(i&j==0)则说明j这样作业尚未被完成。(2)然后将其添加,变成s=i|j,在更新dp[s]。在此我们要设一个标记数组,因为我们并不知道之前s是否已经被更新。

 

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int mm=1<<16;
class node
{public:
  char name[133];
  int s;
  int cost;
}num[30];
class DP
{
  public:
  int min_cost;
  int _tim;
  int pre;
}dp[mm];
int ans[30];
bool vis[mm];
int main()
{
  int cas;
  while(cin>>cas)
  {int n;
    while(cas--)
    { memset(vis,0,sizeof(vis));
      cin>>n;
      for(int i=0;i<n;i++)
      {
        cin>>num[i].name>>num[i].s>>num[i].cost;
      }
      int m=1<<n;
      dp[0].min_cost=0;dp[0].pre=-1;dp[0]._tim=0;//初态
      for(int i=0;i<m;i++)
      {
        for(int j=0;j<n;j++)
        {
          int s=1<<j;
          int tem,cost;
          if((s&i)==0)//挑出未完成j的状态
          {
            tem=s|i;
            cost=dp[i]._tim+num[j].cost-num[j].s;
            if(cost<0)cost=0;
            cost+=dp[i].min_cost;
            if(vis[tem])//更新值
            {
              if(dp[tem].min_cost>cost)
              {
                dp[tem].min_cost=cost;
                dp[tem].pre=j;//记录它的指向工作
                dp[tem]._tim=dp[i]._tim+num[j].cost;
              }
            }
            else
            {
              dp[tem].min_cost=cost;
              dp[tem].pre=j;
              dp[tem]._tim=dp[i]._tim+num[j].cost;
              vis[tem]=1;
            }
          }
        }
      }
      cout<<dp[m-1].min_cost<<"\n";
      int kk=m-1;
      for(int i=0;i<n;i++)
      {
        ans[i]=dp[kk].pre;//回推
        kk=kk^(1<<dp[kk].pre);
      }
      for(int i=n-1;i>=0;i--)
      cout<<num[ans[i]].name<<"\n";
  }
 }
}



 

内容概要:本文介绍了基于贝叶斯优化的CNN-LSTM混合神经网络在时间序列预测中的应用,并提供了完整的Matlab代码实现。该模型结合了卷积神经网络(CNN)在特征提取方面的优势与长短期记忆网络(LSTM)在处理时序依赖问题上的强大能力,形成一种高效的混合预测架构。通过贝叶斯优化算法自动调参,提升了模型的预测精度与泛化能力,适用于风电、光伏、负荷、交通流等多种复杂非线性系统的预测任务。文中还展示了模型训练流程、参数优化机制及实际预测效果分析,突出其在科研与工程应用中的实用性。; 适合人群:具备一定机器学习基基于贝叶斯优化CNN-LSTM混合神经网络预测(Matlab代码实现)础和Matlab编程经验的高校研究生、科研人员及从事预测建模的工程技术人员,尤其适合关注深度学习与智能优化算法结合应用的研究者。; 使用场景及目标:①解决各类时间序列预测问题,如能源出力预测、电力负荷预测、环境数据预测等;②学习如何将CNN-LSTM模型与贝叶斯优化相结合,提升模型性能;③掌握Matlab环境下深度学习模型搭建与超参数自动优化的技术路线。; 阅读建议:建议读者结合提供的Matlab代码进行实践操作,重点关注贝叶斯优化模块与混合神经网络结构的设计逻辑,通过调整数据集和参数加深对模型工作机制的理解,同时可将其框架迁移至其他预测场景中验证效果。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值