Doing Homework(HDU 1074状压dp)
题意:给你n个要做的作业,它们的名字、期限、可完成所需天数(必须连续)在规定期限不能完成要扣分(每天一分)求做作业顺序使扣分最少。
分析:作业数量较少,用状态压缩,做到第i种作业花费的天数dp[i].t,最小扣分dp[i].sc,当前完成作业标号dp[i].now,和之前完成的作业的情况dp[i].par(要求做作业顺序)枚举所有可能的情况,更新。
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = 1000000007;
struct work{
string name;
int d,wt;
}w[20];
struct Case{
int sc,t,now,par;
}dp[1<<15];
int n,ans[1<<15];
void solve(){
for(int i=1;i<(1<<n);++i){
dp[i].sc=INF;
for(int j=n-1;j>=0;--j){
if(i&(1<<j)){
int tmp=i-(1<<j);
int ts=dp[tmp].t+w[j].wt-w[j].d;
if(ts<0)
ts=0;
if(ts+dp[tmp].sc<dp[i].sc){
dp[i].sc=ts+dp[tmp].sc;
dp[i].par=tmp;
dp[i].now=j;
dp[i].t=dp[tmp].t+w[j].wt;
}
}
}
// cout<<dp[i].sc<<endl;
}
int state=(1<<n)-1;
printf("%d\n",dp[state].sc);
for(int i=0;i<n;++i){
ans[i]=dp[state].now;
state=dp[state].par;
}
for(int i=n-1;i>=0;--i){
cout<<w[ans[i]].name<<endl;
}
}
int main()
{
int ca;
scanf("%d",&ca);
while(ca--){
memset(dp,0,sizeof(dp));
scanf("%d",&n);
for(int i=0;i<n;++i)
cin>>w[i].name>>w[i].d>>w[i].wt;
solve();
}
return 0;
}
Doing Homework(HDU 1074状压dp)的更多相关文章
- Doing Homework HDU - 1074 (状压dp)
Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every ...
- D - Doing Homework HDU - 1074 (状压dp)
题目链接:https://cn.vjudge.net/contest/68966#problem/D 具体思路:我们可以把每个情况都枚举出来,然后用递归的形式求出最终的情况. 比如说 我们要求 10 ...
- HDU 1074状压DP
Doing Homework Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- hdu 1074 (状压dp)
题意: 给出几个学科的作业.每个作业剩余的时间.完成每个学科作业的时间.如果在剩余时间内不能完成相应作业 就要扣分 延迟一天扣一分 求最小扣分 解析: 把这些作业进行全排列 求出最小扣分即可 但A( ...
- HDU 4778 状压DP
一看就是状压,由于是类似博弈的游戏.游戏里的两人都是绝对聪明,那么先手的选择是能够确定最终局面的. 实际上是枚举最终局面情况,0代表是被Bob拿走的,1为Alice拿走的,当时Alice拿走且满足变换 ...
- HDU 3001 状压DP
有道状压题用了搜索被队友骂还能不能好好训练了,, hdu 3001 经典的状压dp 大概题意..有n个城市 m个道路 成了一个有向图.n<=10: 然后这个人想去旅行.有个超人开始可以把他扔到 ...
- hdu 2809(状压dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2809 思路:简单的状压dp,看代码会更明白. #include<iostream> #in ...
- hdu 2167(状压dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2167 思路:经典的状压dp题,前后,上下,对角8个位置不能取,状态压缩枚举即可所有情况,递推关系是为d ...
- Engineer Assignment HDU - 6006 状压dp
http://acm.split.hdu.edu.cn/showproblem.php?pid=6006 比赛的时候写了一个暴力,存暴力,过了,还46ms 那个暴力的思路是,预处理can[i][j]表 ...
随机推荐
- springmvc整合redis架构搭建实例
新换环境,又有新东西可以学习了,哈皮! 抽空学习之余看了一下redis,个人对Springmvc的爱是忠贞不渝,所以整理了一下Springmvc整合redis的环境搭建.分享学习. 第一步: 创建ma ...
- IOS调用相机相册
#import "SendViewController.h" //只能打开,没有加载图片的代码,老代码,供参考 #import <MobileCoreServices/UT ...
- 使用 Android Studio 跑新浪微博SDK Demo遇到的问题及解决
概述 这是新浪微博官方 Android SDK Demo 使用 Android Studio 导入.编译并运行通过的版本. 源码:WeiboSdkDemo 官方项目请点击: weibo_android ...
- linux驱动系列之挂载(转)
转自网页:http://www.cnblogs.com/yeahgis/archive/2012/04/05/2432779.html http://www.linuxso.com/command/c ...
- Jplayer(转)
Jplayer必须要加载 1.样式 jplayer.blue.monday.css 2.jq jquery.1.6.2.min.js 当前最新版本为1.6.2 3.jplayer的js jquery ...
- WinForm 控件库
1:Telerik 介绍: Telerik 是保加利亚的一个软件公司,专注于微软.Net平台的表示层与内容管理控件.Telerik 提供高度稳定性和丰富性能的组件产品,并可应用在非常严格的环境中. 现 ...
- Eclipse 调整代码颜色的地方
Editors - Text Editors General-Apperance-Colors and Fonts 各工作区里面的Editor和Syntax Coloring
- 1028-Digital Roots
描述 The digital root of a positive integer is found by summing the digits of the integer. If the resu ...
- Nginx、LVS及HAProxy负载均衡软件的优缺点详解
http://www.csdn.net/article/2014-07-24/2820837
- mysql查看数据库命令
mysql查看数据库命令 打开的数据库的命令 mysql> use mysql Database changed 查看数据库的命令 mysql> show databases; 查看数据表 ...