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 }
  • 相关阅读:
    ectouch第四讲 之缓存文件的生成
    ectouch第三讲之加载调用机制
    Ubuntu 16.04下安装sublime Text的插件
    有关于Git操作(持续更新)
    MongoDB简单查询语句<平时使用语录,持续更新>
    Ruby小白入门笔记之<Rubymine工具的快捷键>
    Ruby小白入门笔记之 <Gemfile 文件>
    Ubuntu 16.04安装、卸载mysql及怎么使用SQL常用操作语句
    Git中.gitignore忽略文件(maven项目)
    Git入门之常用命令(转载阮一峰老师)
  • 原文地址:https://www.cnblogs.com/yoyo-sincerely/p/5095335.html
Copyright © 2011-2022 走看看