zoukankan      html  css  js  c++  java
  • HDU_2019 选课时间(题目已修改,注意读题)(生成函数)

      貌似跟1171一样的,呃。。。

    My Code:

    #include <iostream>
    #include <cstring>
    #include <cstdio>

    using namespace std;

    const int N = 100;

    struct node {
    int val;
    int num;
    } a[55];

    int c1[N], c2[N];


    int main() {
    //freopen("data.in", "r", stdin);

    int t, n, i, j, sum, k, m;
    while(cin >> t) {
    while(t--) {
    scanf("%d%d", &n, &m);
    for(i = 1; i <= m; ++i) {
    scanf("%d%d", &a[i].val, &a[i].num);
    }
    for(i = 0; i <= n; i++) {
    c1[i] = 1; c2[i] = 0;
    }
    sum = a[1].val * a[1].num;
    for(i = 2; i <= m; ++ i) {
    for(j = 0; j <= n && j <= sum; ++ j) {
    for(k = 0; k + j <= n && k <= a[i].val * a[i].num; k += a[i].val) {
    c2[k+j] += c1[j];
    }
    }
    sum += a[i].val * a[i].num;
    for(j = 0; j <= sum && j <= n; ++ j) {
    c1[j] = c2[j]; c2[j] = 0;
    }
    }
    printf("%d\n", c1[n]);
    }
    }
    return 0;
    }
  • 相关阅读:
    29 求和
    28 跳转控制语句 goto
    27 跳转控制语句 continue
    26 跳转控制语句 break
    25 打印金字塔
    24 打印九九乘法表
    23 多重循环控制
    22 do-while 循环
    21 while 循环
    20 for循环控制
  • 原文地址:https://www.cnblogs.com/vongang/p/2262017.html
Copyright © 2011-2022 走看看