zoukankan      html  css  js  c++  java
  • DP poj3211 Washing Clothes 01背包

    连接:http://poj.org/problem?id=3211

    俩人只能一起溪一中衣服也就是说两人洗的时候就是01背包就是,然后吧各种衣服所用时间相加。。。

    View Code
     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 struct node
     5 {
     6     char color[20];
     7     int sum;
     8     int a[105];
     9     int count;
    10 }col[15];
    11 int count;
    12 int search(char s[],int m)
    13 {
    14     int i;
    15     for(i = 0;i < m;i++)
    16     if(strcmp(s,col[i].color) == 0)
    17     return i;
    18 
    19     return 0;
    20 }
    21 int main()
    22 {
    23     char str[15];
    24     int m,n,i,j,a,k;
    25     int f[2000];
    26     while(scanf("%d %d",&m,&n) && n||m)
    27     {
    28         count = 0;
    29         for(i = 0;i < m;i++)
    30         {
    31             scanf("%s",col[i].color);
    32             col[i].sum = 0;
    33             col[i].count = 0;
    34         }
    35         for(i = 0;i < n;i++)
    36         {
    37             scanf("%d %s",&a,str);
    38             int leap;
    39             leap = search(str,m);
    40             int tag;
    41             tag = col[leap].count;
    42             col[leap].a[tag] = a;
    43             col[leap].sum += a;
    44             col[leap].count++;
    45 
    46         }
    47 
    48         int sum = 0;
    49         for(i = 0;i < m;i++)
    50         {
    51             memset(f,0,sizeof(f));
    52             int v = col[i].sum/2;
    53             for(j = 0;j < col[i].count;j++)
    54             for(k = v;k >= col[i].a[j];k--)
    55             if(f[k] < f[k-col[i].a[j]]+col[i].a[j])
    56             f[k] = f[k-col[i].a[j]]+col[i].a[j];
    57 
    58 
    59             sum += col[i].sum-f[v];
    60         }
    61         printf("%d\n",sum);
    62 
    63     }
    64     return 0;
    65 }
  • 相关阅读:
    hdu 2147博弈找规律
    hdu 1851 巴什博弈
    hdu 1729 sg博弈
    hdu 2516博弈找规律
    (转载)博弈之SG函数
    poj 2234基础Nim博弈||sg博弈
    hdu 1730 sg博弈||nim博弈
    hdu 1847 博弈找规律
    n hdu 1760 [SG博弈]二维状态
    hdu 1849 nim博弈
  • 原文地址:https://www.cnblogs.com/0803yijia/p/2649809.html
Copyright © 2011-2022 走看看