码迷,mamicode.com
首页 > 其他好文 > 详细

hdu1085

时间:2017-11-11 14:45:27      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:for   ret   ring   i++   set   pac   code   cin   sizeof   

/*
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int c1[8010], c2[8010];
int main() {
  int s[4], v[4] = {0, 1, 2, 5};
  while (scanf("%d%d%d", &s[1], &s[2], &s[3]) != EOF) {
      if (s[1] == 0 && s[2] == 0 && s[3] == 0) break;
      int sum = 0;
      sum+=s[1] + s[2]*v[2] + s[3]*v[3];
        memset(c1, 0, sizeof(c1));
        for (int i = 0; i <= s[1]; i++) {
            c1[i] = 1;
        }
        memset(c2, 0, sizeof(c2));
        for (int i = 2; i <= 3; i++) {
            for (int j = 0; j <= sum; j++) {
                for (int k = 0, count = 0; count<=s[i]&&k+j <= sum; k+=v[i], count++) {
                    c2[k+j] += c1[j];
                }
            }
            for (int j = 0; j<= sum; j++) {
                c1[j] = c2[j];
                c2[j] = 0;
            }
        }
    for(int j=0; j <= sum; j++){
            if(c1[j]==0){
                printf("%d\n",j);
                break;
            }
        }
    }
}*/
#include<iostream>
#include<cstring>
using namespace std;
const int MAX = 8000;
int arr[MAX+10], brr[MAX+10];
int main() {
  int s[4];
  int v[4]={0, 1, 2, 5};
  while (cin>>s[1]>>s[2]>>s[3]) {
    if (s[1]==0&&s[2]==0&&s[3]==0)
      return 0;
    int n = 0;
    for (int i = 1; i <= 3; i++)
      n+=s[i]*v[i];
    memset(arr,0,sizeof(arr));
    memset(brr,0,sizeof(brr));
    arr[0] = 1;
    for (int i = 1; i <= 3; i++) {
      for (int j = 0; j <= n; j++) {
        for (int k =0, count = 0; count <= s[i] && j+k <= n; k+=v[i],count++) {
          brr[j+k] += arr[j];
        }
      }
      for (int l =0; l <= n; l++) {
        arr[l] = brr[l];
        brr[l] = 0;
      }
    }
    int a;
    for (a = 1; a <= n; a++) {
      if (arr[a] == 0)
        break;
    }    
    cout<<a<<endl;
  }
  return 0;
} 

 

hdu1085

标签:for   ret   ring   i++   set   pac   code   cin   sizeof   

原文地址:http://www.cnblogs.com/a863886199/p/7818963.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!