zoukankan      html  css  js  c++  java
  • uva 10910(子集和问题)

    Marks Distribution

    Time limit: 3.000 seconds

    In an examination one student appeared in N subjects and has got total T marks. He has passed in all the Nsubjects where minimum mark for passing in each subject is P. You have to calculate the number of ways the student can get the marks. For example, if N=3T=34 and P=10 then the marks in the three subject could be as follows.

     

    Subject 1

    Subject 2

    Subject 3

    1

    14

    10

    10

    2

    13

    11

    10

    3

    13

    10

    11

    4

    12

    11

    11

    5

    12

    10

    12

    6

    11

    11

    12

    7

    11

    10

    13

    8

    10

    11

    13

    9

    10

    10

    14

    10

    11

    12

    11

    11

    10

    12

    12

    12

    12

    12

    10

    13

    10

    13

    11

    14

    11

    13

    10

    15

    10

    14

    10

    So there are 15 solutions. So F (3, 34, 10) = 15.

    Input

    In the first line of the input there will be a single positive integer K followed by K lines each containing a single test case. Each test case contains three positive integers denoting NT and P respectively. The values of NT and P will be at most 70. You may assume that the final answer will fit in a standard 32-bit integer.

    Output

    For each input, print in a line the value of F (N, T, P).

    Sample Input

    Output for Sample Input

    2
    3 34 10
    3 34 10

    15
    15

    思路:过程的最后一步为前n门课总分为j的种类;

        最后一步的子问题为:前n-1门课总分为j-k的种类;

        显然;k>=p&&k<=j-p*(n-1);(保证每门课都能取到最低值);

        状态转移方程为:dp[i][j]+=dp[i-1][j-k];

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<iomanip>
     7 #include<cmath>
     8 #include<vector>
     9 #include<queue>
    10 #include<stack>
    11 using namespace std;
    12 #define PI 3.141592653589792128462643383279502
    13 int dp[75][75];
    14 int n;
    15 int main(){
    16     //#ifdef CDZSC_June
    17     //freopen("in.txt","r",stdin);
    18     //#endif
    19     //std::ios::sync_with_stdio(false);
    20     cin>>n;
    21     int N,T,P;
    22     while(n--){
    23         cin>>N>>T>>P;
    24 
    25         memset(dp,0,sizeof(dp));
    26         for(int i=0;i<=70;i++)dp[1][i]=1;
    27         for(int i=2;i<=N;i++)
    28         for(int j=P;j<=T;j++){
    29             for(int k=P;k<=j-P*(i-1);k++)
    30             dp[i][j]+=dp[i-1][j-k];
    31         }
    32     cout<<dp[N][T]<<endl;
    33     }
    34     return 0;
    35 }
  • 相关阅读:
    操作系统知识
    接下来 的 重点 是 运维
    并行计算 排序 是 分布式数据库 能否 突破 传统 数据库 性能 瓶颈 的 关键
    并行计算 是 趋势
    高并发 分布式 架构 的 几大 基本要素
    堆栈趣话
    虚拟机 操作系统 容器
    Lambda 表达式 是 个 好东东
    update set from 语句用法 delete 多表删除的使用 以及异常:table name "temp_new_tel" specified more than once
    我的面试
  • 原文地址:https://www.cnblogs.com/yoyo-sincerely/p/5095335.html
Copyright © 2011-2022 走看看