zoukankan      html  css  js  c++  java
  • hdu1085

    /*
    #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
    ",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;
    } 
  • 相关阅读:
    常用知识点集合
    LeetCode 66 Plus One
    LeetCode 88 Merge Sorted Array
    LeetCode 27 Remove Element
    LeetCode 26 Remove Duplicates from Sorted Array
    LeetCode 448 Find All Numbers Disappeared in an Array
    LeetCode 219 Contains Duplicate II
    LeetCode 118 Pascal's Triangle
    LeetCode 119 Pascal's Triangle II
    LeetCode 1 Two Sum
  • 原文地址:https://www.cnblogs.com/a863886199/p/7818963.html
Copyright © 2011-2022 走看看