hdu 1074 Doing Homework (状态压缩dp)

本文介绍了一个作业调度问题,通过状态压缩动态规划求解最优作业完成顺序,以最小化因延期提交而产生的分数损失。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Doing Homework

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


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.
 


题目大意:有n门课程,每门课程有一个最晚提交时间和完成所需时间。
每超时一天扣一分。问最少扣多少分,输出安排的顺序。

分析:因为n最大是15,那么方案数为15!,所以数组开不下要进行状态压缩。
可以压缩成2^15.  这样的话1代表完成0代表位完成。就可以进行dp了。

AC代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define inf 1<<30
struct tree
{
	char name[101];
	int deadline;
	int t;
}p[50];
int dp[1<<15];
int dpt[1<<15];
int pre[1<<15];
void pf(int n)
{
	if(n!=0)
	{
		pf(n-(1<<pre[n]));
		printf("%s\n",p[pre[n]].name);
	}
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int n;
		memset(pre,-1,sizeof(pre));
		memset(dpt,0,sizeof(dpt));
		scanf("%d",&n);
		for(int i=0;i<n;i++)
		{
			scanf("%s%d%d",p[i].name,&p[i].deadline,&p[i].t);
		}
		int n1=1<<n;
		for(int i=0;i<n1;i++) //不知道为什么这里加上等号就会WA讲道理没有影响才对
		dp[i]=inf;
		dp[0]=0;
		for(int i=1;i<n1;i++)
		{
			for(int j=n-1;j>=0;j--) //因为是按字典序输入,所以反过来就能字典序输出,也可以用sort实现
			{
				int k=1<<j;
				if(!(i&k))continue;  //当未完成k任务时跳出
				int time=dpt[i-k]+p[j].t-p[j].deadline;
				if(time<0)
				time=0;
				if(dp[i]>dp[i-k]+time)
				{
					dp[i]=dp[i-k]+time;
					pre[i]=j;
					dpt[i]=dpt[i-k]+p[j].t;
				}
			}
		}
		printf("%d\n",dp[n1-1]);
		pf(n1-1);
	} 
} 

内容概要:本文探讨了在MATLAB/SimuLink环境中进行三相STATCOM(静态同步补偿器)无功补偿的技术方法及其仿真过程。首先介绍了STATCOM作为无功功率补偿装置的工作原理,即通过调节交流电压的幅值和相位来实现对无功功率的有效管理。接着详细描述了在MATLAB/SimuLink平台下构建三相STATCOM仿真模型的具体步骤,包括创建新模型、添加电源和负载、搭建主电路、加入控制模块以及完成整个电路的连接。然后阐述了如何通过对STATCOM输出电压和电流的精确调控达到无功补偿的目的,并展示了具体的仿真结果分析方法,如读取仿真数据、提取关键参数、绘制无功功率变化曲线等。最后指出,这种技术可以显著提升电力系统的稳定性与电能质量,展望了STATCOM在未来的发展潜力。 适合人群:电气工程专业学生、从事电力系统相关工作的技术人员、希望深入了解无功补偿技术的研究人员。 使用场景及目标:适用于想要掌握MATLAB/SimuLink软件操作技能的人群,特别是那些专注于电力电子领域的从业者;旨在帮助他们学会建立复杂的电力系统仿真模型,以便更好地理解STATCOM的工作机制,进而优化实际项目中的无功补偿方案。 其他说明:文中提供的实例代码可以帮助读者直观地了解如何从零开始构建一个完整的三相STATCOM仿真环境,并通过图形化的方式展示无功补偿的效果,便于进一步的学习与研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值