当前位置:码农谷 > 算法与程序 > POJ 3211 Washing Clothes:题目解答源码

POJ 3211 Washing Clothes:题目解答源码

所属学科:C语言 - 编译预处理 难度: 关注度:28

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?

输入描述

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.

输出描述

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

程序源码

完整的源代码如下:

#include "stdio.h"#include "string.h"#include "algorithm"using namespace std;struct clothes{	char color[12]; // 每种衣服颜色	int num; //每种衣服的数量	int sum; //洗每种衣服所用总时间	int time[105]; //这种衣服中每一件用的时间}clo[11];int main(){	int m, n, i, j, k, time;	int dp[500005];    char color[12];	while(~scanf("%d%d", &m, &n) && (m + n))	{		for(i = 0; i < m; i++)		{

关注微信,获得更多免费资源
关于我们   |   免责声明   |   联系我们   |   网站地图   |   HR交流群   |   学生交流群   |   教师交流群

码农谷   版权所有 © 2015-2017   湘ICP备16018319号-1