zoukankan      html  css  js  c++  java
  • HDU 1171 Big Event in HDU 生成函数

    #include <bits/stdc++.h>
    #define DBG(x) cerr << #x << " = " << x << endl
    
    typedef long long LL;
    using namespace std;
    const int MAX_SUM = 250000 + 16;
    const int N = 128;
    LL ans[MAX_SUM], tmp[MAX_SUM];
    int num[N], v[N];
    int main(int argc, char **argv) {
        int n;
        while(~scanf("%d", &n) && n >= 0) {
            int tot = 0;
            for(int i = 1; i <= n; ++i) {
                scanf("%d%d", &v[i], &num[i]);
                tot += v[i] * num[i];
            }
            memset(ans, 0, sizeof(ans));
            memset(tmp, 0, sizeof(tmp));
            for(int i = 0; i <= num[1]; ++i) ans[i * v[1]] = 1;
            for(int i = 2; i <= n; ++i) {
              for(int e = 0; e <= tot; ++e) 
    			  for(int take = 0; take <= num[i] && e + take * v[i] <= tot; ++take)
                    tmp[e + take * v[i]] += ans[e];
                memcpy(ans, tmp, sizeof(tmp));
                memset(tmp, 0, sizeof(tmp));
            }
            int l = tot, r = 0, diff = tot;
            for(int i = 0; i <= tot; ++i) if(ans[i]) {
                int ll = i, rr = tot - i;
                int df = abs(rr - ll);
                if(ll >= rr && df < diff) {
                    l = ll;
                    r = rr;
                    diff = df;
                }
            }
            printf("%d %d
    ", l, r);
        }
        return 0;
    }
    
  • 相关阅读:
    安卓中期小作业
    安卓大作业UI预定搞
    实验3
    实验一总结
    实验8 SQLite数据库操作
    实验6 在应用程序中播放音频和视频
    实验4 颜色、字符串资源的使用
    实验四
    实验三
    实验二
  • 原文地址:https://www.cnblogs.com/ToRapture/p/7453456.html
Copyright © 2011-2022 走看看