Time Limit: 1000MS | Memory Limit: 131072K | |
Total Submissions: 8268 | Accepted: 2565 |
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 M strings 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
题意:
两人一起洗衣服,每次洗只能洗相同的颜色,求最短洗完衣服的时间。
思路:
01背包。两人同样一起洗衣服,所以对于一种颜色的衣服最好能平均分配时间,不能平均则两人时间最接近且最接近平均总时间。
AC:
#include<stdio.h> #include<string.h> typedef struct { char color[15]; //存颜色的名字 int sumtime; //存总时间 int sumnum; //存总件数 int each[105]; //存每一件的时间 }node; node no[15]; int dp[100000]; int main() { int n,m,ans; while(scanf("%d%d",&n,&m)!=EOF&&(n+m)) { ans=0; memset(no,0,sizeof(no)); for(int i=1;i<=n;i++) { scanf("%s",no[i].color); no[i].sumnum=0; no[i].sumtime=0; } //颜色种类 for(int i=1;i<=m;i++) { int t; char str[15]; scanf("%d%s",&t,str); for(int j=1;j<=n;j++) if(!strcmp(str,no[j].color)) { no[j].sumnum++; no[j].each[no[j].sumnum]=t; no[j].sumtime+=t; } } //输入每件衣服资料 for(int k=1;k<=n;k++) { memset(dp,0,sizeof(dp)); int half=no[k].sumtime/2; for(int i=1;i<=no[k].sumnum;i++) for(int j=half;j>=no[k].each[i];j--) if(dp[j]<dp[j-no[k].each[i]]+no[k].each[i]) dp[j]=dp[j-no[k].each[i]]+no[k].each[i]; ans+=(no[k].sumtime-dp[half]); } //01背包 printf("%d\n",ans); } return 0; }
相关推荐
POJ3211--Washing Clothes
这是关于这三个问题的详解文档 包括了完整代码 和 详细解释
基于FPGA的洗衣机系统设计,用的是VerilogHDL语言
washingmachine.fis
washing_machine_retro
精品ppt模板工业形象washing_machine_retro019
设计要求: (1) 设计一个电子定时器,控制洗衣机做如下运转:定时启动正转25s暂停5s反转25s暂停5s如果定时未到,则回到“正转25s暂停5s……”,定时到则停止。 (2) 若定时到,则停机发出音响信号。...
洗衣机程序c语言程序有辅助说明 洗衣机程序c语言程序有辅助说明
washingmachine
关于Abaqus官方流固耦合实例Front-load washing machine我的实现版本。包含ace和inp文件。设置了1积分挡爬虫(其实如果爬评论可以看到百度网盘的链接哒!
I had to wait in today for a new washing machine to be delivered, so had a few hours to spare. So decided it might be fun to try and create a nice WPF screensaver. This article is the outcome of this....
51单片机程序,独立按键控制继电器开关,通过控制2个继电器循环工作状态,模拟洗衣机间歇正反转 一般正转3s,停止2s,然后反转3s,停止2s,循环上述动作
PLC 洗衣机 设计要求,设计步骤,总结等 在硬件上实现过
设计一种自动洗衣机的程序控制器,在启动后先进水,等到达高水位后,启动洗衣马达转动4min,如在洗衣过程中发现水位低于高水位,则停止洗衣马达转动并报警,并在水位到达高水位后再次启动马达。...
一个全自动洗衣机,三个状态及显示。 开发环境为xilinx ise
一个简单的洗衣机VHDL程序,简化了过程,主要体现状态机的工作方式
who_is_washing 家务图表
用AT89S52实现简单的洗衣过程,水位的高低显示和设定,洗衣方式的选择,洗衣结束蜂鸣器报警功能
基于单片机的洗衣机源代码,正反转,脱水,紫外消毒,异常报警等
洗衣机控制器的设计,实现以下功能:A) 设计一个电子定时器,定时时间为99秒,控制洗衣机作如下运转:启动→正转 20 秒→暂停 10 秒→反转 20 秒→暂停 10 秒→定时时间未到回到“正转 20 秒→暂停 10 秒→……”,...