题目链接:

这个题目比1711难处理的是字符串怎样处理,所以我们要想办法,自然而然就要想到用结构体存储。所以最后将全部的衣服分组,然后将每组时间减半,看最多能装多少。最后求最大值。那么就非常愉快的转化成了一个01背包问题了。。。

hdu1711是说两个得到的价值要尽可能的相等。所以还是把全部的价值分为两半。最后01背包,那么这个问题就得到了解决。。

题目:

Washing Clothes
Time Limit: 1000MS   Memory Limit: 131072K
Total Submissions: 8637   Accepted: 2718

Description

Dearboy was so busy recently that now he has piles of clothes to wash. Luckily, he has a beautiful and hard-working girlfriend to help him. The clothes are in varieties of colors but each piece of them can be seen as of only one color. In order to prevent
the clothes from getting dyed in mixed colors, Dearboy and his girlfriend have to finish washing all clothes of one color before going on to those of another color.

From experience Dearboy knows how long each piece of clothes takes one person to wash. Each piece will be washed by either Dearboy or his girlfriend but not both of them. The couple can wash two pieces simultaneously. What is the shortest possible time they
need to finish the job?

Input

The input contains several test cases. Each test case begins with a line of two positive integers M and N (M < 10, N < 100), which are the numbers of colors and of clothes. The next line contains Mstrings which
are not longer than 10 characters and do not contain spaces, which the names of the colors. Then follow N lines describing the clothes. Each of these lines contains the time to wash some piece of the clothes (less than 1,000) and its color. Two zeroes
follow the last test case.

Output

For each test case output on a separate line the time the couple needs for washing.

Sample Input

3 4
red blue yellow
2 red
3 blue
4 blue
6 red
0 0

Sample Output

10

Source

代码为:

#include<cstdio>
#include<map>
#include<iostream>
#include<cstring>
using namespace std; const int maxn=100000+10;
int dp[maxn]; struct clothes
{
int num;//颜色同样的衣服的编号
int sum;//颜色形同的衣服的总数
char color[100];//颜色
int time[105];//颜色同样的不同衣服的时间
}clo[10+10]; int main()
{
int m,n,u,max_pack,ans;
char str[100+10];
while(~scanf("%d%d",&m,&n))
{
if(n==0&&m==0) return 0;
for(int i=1;i<=m;i++)
{
scanf("%s",clo[i].color);
clo[i].num=1;
clo[i].sum=0;
}
for(int i=1;i<=n;i++)
{
scanf("%d%s",&u,str);
for(int j=1;j<=m;j++)
{
if(strcmp(str,clo[j].color)==0)
{
int tmp=clo[j].num;
clo[j].time[tmp]=u;
clo[j].sum=clo[j].sum+u;
clo[j].num++;
}
}
}
for(int i=1;i<=m;i++)
clo[i].num--;
ans=0;
for(int i=1;i<=m;i++)
{
memset(dp,0,sizeof(dp));
max_pack=clo[i].sum/2;
for(int j=1;j<=clo[i].num;j++)
for(int k=max_pack;k>=clo[i].time[j];k--)
dp[k]=max(dp[k],dp[k-clo[i].time[j]]+clo[i].time[j]);
ans=ans+max(dp[max_pack],clo[i].sum-dp[max_pack]);
}
cout<<ans<<endl;
}
return 0;
}

hdu1171 题目:

Big Event in HDU

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 23302    Accepted Submission(s): 8206

Problem Description
Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don't know that Computer College had ever been split into Computer College and Software College in 2002.

The splitting is absolutely a big event in HDU! At the same time, it is a trouble thing too. All facilities must go halves. First, all facilities are assessed, and two facilities are thought to be same if they have the same value. It is assumed that there is
N (0<N<1000) kinds of facilities (different value, different kinds).
 
Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 50 -- the total number of different facilities). The next N lines contain an integer V (0<V<=50 --value of facility) and an integer M (0<M<=100 --corresponding number of the
facilities) each. You can assume that all V are different.

A test case starting with a negative integer terminates input and this test case is not to be processed.
 
Output
For each case, print one line containing two integers A and B which denote the value of Computer College and Software College will get respectively. A and B should be as equal as possible. At the same time, you should guarantee that A is not less than B.
 
Sample Input
2
10 1
20 1
3
10 1
20 2
30 1
-1
 
Sample Output
20 10
40 40
 
Author
lcy
 
Recommend
We have carefully selected several similar problems for you:  2159 2955 1087 1069 1231 
 

代码为

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; const int maxn=250000+10;
int dp[maxn]; int sum[50+10],val[50+10];
int kind[5000+10]; int main()
{
int n,max_pack,ans,cal,Max;
while(~scanf("%d",&n))
{
memset(dp,0,sizeof(dp));
if(n<=0) return 0;
cal=1;
max_pack=0;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&val[i],&sum[i]);
max_pack+=sum[i]*val[i];
for(int j=1;j<=sum[i];j++)
{
kind[cal]=val[i];
cal++;
}
}
cal--;
Max=max_pack/2;
for(int i=1;i<=cal;i++)
for(int j=Max;j>=kind[i];j--)
dp[j]=max(dp[j],dp[j-kind[i]]+kind[i]);
ans=max(dp[Max],max_pack-dp[Max]);
cout<<ans<<" "<<max_pack-ans<<endl;
}
return 0;
}

poj3211Washing Clothes(字符串处理+01背包) hdu1171Big Event in HDU(01背包)的更多相关文章

  1. hdu1171Big Event in HDU(01背包)

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  2. hdu 1171 Big Event in HDU (01背包, 母函数)

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  3. HUD 1171 Big Event in HDU(01背包)

    Big Event in HDU Problem Description Nowadays, we all know that Computer College is the biggest depa ...

  4. HDU1171--Big Event in HDU(多重背包)

    Big Event in HDU   Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...

  5. HDU 1171 Big Event in HDU 多重背包二进制优化

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1171 Big Event in HDU Time Limit: 10000/5000 MS (Jav ...

  6. HDU1171-Big Event in HDU

    描述: Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don ...

  7. HDU 1171 Big Event in HDU dp背包

    Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s ...

  8. HDU - 1171 Big Event in HDU 多重背包

    B - Big Event in HDU Nowadays, we all know that Computer College is the biggest department in HDU. B ...

  9. HDU 1171 Big Event in HDU (多重背包变形)

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

随机推荐

  1. Linux内核中TCP SACK机制远程DoS预警通告

    漏洞描述 2019年6月18日,RedHat官网发布报告:安全研究人员在Linux内核处理TCP SACK数据包模块中发现了三个漏洞,CVE编号为CVE-2019-11477.CVE-2019-114 ...

  2. CAD参数绘制批注(com接口)

    C#中实现代码说明: private void DrawComment() { MxDrawComment com = new MxDrawComment(); MxDrawPoint pt = ne ...

  3. [转载]MyBatis mapper文件中的变量引用方式#{}与${}的差别

    转载自:http://blog.csdn.net/szwangdf/article/details/26714603 默认情况下,使用#{}语法,MyBatis会产生PreparedStatement ...

  4. java.util.MissingResourceException: Can't find bundle for base name db, locale zh_CN

    在使用Bundle来加载配置文件的时候, 爆出了这个错误: 原因? 没有找到需要加载的配置文件,因为配置文件必须放在src目录下面, 如果放进了com.bj186.crm的包下面,就必须添加包的名称到 ...

  5. asp.net C# 获得配置文件AppSettings 的值

    using System.Configuration;//导入命名空间 //配置文件 Web.config <appSettings> <!--数据连接字符串--> <a ...

  6. [JOYOI] 1052 没有上司的舞会

    / Joy OI / 题目列表 / 没有上司的舞会 题目限制 时间限制 内存限制 评测方式 题目来源 1000ms 131072KiB 标准比较器 Local 题目描述 Ural大学有N个职员,编号为 ...

  7. 常用的四种设计模式 PHP代码

    // 工厂模式 interface Iuser { public function getUserName(); } class UserFactory { static public functio ...

  8. python爬虫入门02:教你通过 Fiddler 进行手机抓包

    哟~哟~哟~ hi起来 everybody 今天要说说怎么在我们的手机抓包 通过 python爬虫入门01:教你在Chrome浏览器轻松抓包 我们知道了 HTTP 的请求方式 以及在 Chrome 中 ...

  9. 版本控制git之一 仓库管理 安装 基础

      版本控制git之一-仓库管理 git ​ 再开始这个话题之前,让我想起了一件很痛苦的事情,在我大学写毕业论文的时候,我当时的文件是这样保存的 毕业论文_初稿.doc 毕业论文_修改1.doc 毕业 ...

  10. 一种RC滤波电路的验证

    在做电源的时候,在开关管的D极经常是出现不想看到的尖峰脉冲.以CCFL推挽式缓冲电路为准,我与一个同学杨进行了相应的验证. 其中的出来的现象和反思如下: 1,加上电阻和电容串联的滤波的确能将尖峰脉冲消 ...