题意:有n门课,每门课有截止时间和完成所需的时间,如果超过规定时间完成,每超过一天就会扣1分,问怎样安排做作业的顺序才能使得所扣的分最小

思路:二进制表示。

 #include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long
#define clc(a,b) memset(a,b,sizeof(a))
const int MAXN=<<;
struct node
{
int cost;
int pre;
int reduced;
} dp[MAXN];
bool visited[MAXN];
struct course
{
int deadtime;
int cost;
char name[];
} course[];
void output(int status)
{
int curjob=dp[status].pre^status;
int curid=;
curjob>>=;
while(curjob)
{
curid++;
curjob>>=;
}
if(dp[status].pre!=)
{
output(dp[status].pre);
}
printf("%s\n",course[curid].name);
}
int main()
{
// freopen("in.txt","r",stdin);
int T,n;
int i,j;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
int upper=<<n;
int dayupper=;
for(i=; i<n; i++)
{
scanf("%s%d%d",&course[i].name,&course[i].deadtime,&course[i].cost);
dayupper+=course[i].cost;
}
memset(visited,false,sizeof(visited));
dp[].cost=;
dp[].pre=-;
dp[].reduced=;
visited[]=true;
int work;
int tupper=upper-;
for(j=; j<tupper; j++)
{
for(work=; work<n; work++)
{
int cur=<<work;
if((cur&j)==)
{
int curtemp=cur|j;
int day=dp[j].cost+course[work].cost;
dp[curtemp].cost=day;
int reduce=day-course[work].deadtime;
if(reduce<)reduce=;
reduce+=dp[j].reduced;
if(visited[curtemp])
{
if(reduce<dp[curtemp].reduced)
{
dp[curtemp].reduced=reduce;
dp[curtemp].pre=j;
}
}
else
{
visited[curtemp]=true;
dp[curtemp].reduced=reduce;
dp[curtemp].pre=j;
}
}
}
}
printf("%d\n",dp[tupper].reduced);
output(tupper);
}
}

HDU 1074 Doing Homework(状态压缩DP)的更多相关文章

  1. HDU 1074 Doing Homework (状态压缩 DP)

    题目大意: 有 n 项作业需要完成,每项作业有上交的期限和需完成的天数,若某项作业晚交一天则扣一分.输入每项作业时包括三部分,作业名称,上交期限,完成所需要的天数.求出完成所有作业时所扣掉的分数最少, ...

  2. hdu1074 Doing Homework(状态压缩DP Y=Y)

    Doing Homework Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  3. HDU 4511 (AC自动机+状态压缩DP)

    题目链接:  http://acm.hdu.edu.cn/showproblem.php?pid=4511 题目大意:从1走到N,中间可以选择性经过某些点,比如1->N,或1->2-> ...

  4. HDU 1074 Doing Homework(像缩进DP)

    Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of h ...

  5. HDU 3001 Travelling(状态压缩DP+三进制)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3001 题目大意:有n个城市,m条路,每条路都有一定的花费,可以从任意城市出发,每个城市不能经过两次以上 ...

  6. hdu 4057(ac自动机+状态压缩dp)

    题意:容易理解... 分析:题目中给的模式串的个数最多为10个,于是想到用状态压缩dp来做,它的状态范围为1-2^9,所以最大为2^10-1,那我们可以用:dp[i][j][k]表示长度为i,在tri ...

  7. hdu 2825(ac自动机+状态压缩dp)

    题意:容易理解... 分析:在做这道题之前我做了hdu 4057,都是同一种类型的题,因为题中给的模式串的个数最多只能为10个,所以我们就很容易想到用状态压缩来做,但是开始的时候我的代码超时了dp时我 ...

  8. Hdu 4778 Gems Fight! (状态压缩 + DP)

    题目链接: Hdu 4778 Gems Fight! 题目描述: 就是有G种颜色,B个背包,每个背包有n个宝石,颜色分别为c1,c2............两个人轮流取背包放到公共容器里面,容器里面有 ...

  9. HDU1074 Doing Homework 状态压缩dp

    题目大意: 根据完成任务的截止时间,超时一天罚1分,求完成所有任务后的最小罚时 这里n最大为15,可以利用状态压缩来解决问题 /* 首先要明白的一点是状态1/0分别表示这件事做了还是没做 而1/0的位 ...

随机推荐

  1. 用JavaScript获取页面上被选中的文字的技巧

    这里介绍的一个小技巧是如何用JavaScript获取页面上被选中的文字的方法.最关键的JavaScript API是: event.selection = window.getSelection(); ...

  2. jquery 请求jsp传递json数据的方法

    $(function() { $("a[name=hrefID]").click(function() { var id = $(this).attr("id" ...

  3. POJ1151+线段树+扫描线

    /* 线段树+扫描线+离散化 求多个矩形的面积 */ #include<stdio.h> #include<string.h> #include<stdlib.h> ...

  4. [Ruby on Rails系列]5、专题:Talk About SaSS

    This is my presentation in the Rails lecture of Hosei University. I will introduce SaSS by 5 example ...

  5. IDEA 创建maven-web project失败一例

    今天使用IDEA创建WEB-APP总是失败,经排查原来是MAVEN环境没配置好!!! 配置: M2_HOME--->maven解压目录 path---->%M2_HOME%\bin\

  6. MVC 文件上传和图片剪辑

    http://www.cnblogs.com/hinton/archive/2012/03/01/2375465.html http://gallery.kissyui.com/uploader/1. ...

  7. 117. Populating Next Right Pointers in Each Node II

    题目: Follow up for problem "Populating Next Right Pointers in Each Node". What if the given ...

  8. android SharedPreferences 使用

    除了SQLite数据库外,SharedPreferences也是一种轻型的数据存储方式,它的本质是基于XML文件存储key-value键值 对数据,通常用来存储一些简单的配置信息.其存储位置在/dat ...

  9. 爬虫实现(hpricot)

    1.基本代码 在gemfile中加入gem "hpricot",bundler install之后,在application.rb中require "hpricot&qu ...

  10. linux 查看系统信息命令

    linux 查看系统信息命令是linux初学者必备的基础知识, 这些命令也非常有用, 因为进入linux第一件事就可能是首先查看系统信息, 因此必要的系统的学习一下这些linux系统信息命令还是非常有 ...