• Codeforces Round #302 (Div. 2) C. Writing Code 简单dp


    C. Writing Code

    Time Limit: 20 Sec  Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/544/problem/C

    Description


    Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, the i-th of them makes exactly ai bugs in every line of code that he writes.

    Let's call a sequence of non-negative integers v1, v2, ..., vn a plan, if v1 + v2 + ... + vn = m. The programmers follow the plan like that: in the beginning the first programmer writes the first v1 lines of the given task, then the second programmer writes v2 more lines of the given task, and so on. In the end, the last programmer writes the remaining lines of the code. Let's call a plan good, if all the written lines of the task contain at most b bugs in total.

    Your task is to determine how many distinct good plans are there. As the number of plans can be large, print the remainder of this number modulo given positive integer mod.

    Input

    The first line contains four integers n, m, b, mod (1 ≤ n, m ≤ 500, 0 ≤ b ≤ 500; 1 ≤ mod ≤ 109 + 7) — the number of programmers, the number of lines of code in the task, the maximum total number of bugs respectively and the modulo you should use when printing the answer.

    The next line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 500) — the number of bugs per line for each programmer.

    Output

    Print a single integer — the answer to the problem modulo mod.

    Sample Input

    3 3 3 100
    1 1 1

    Sample Output

    10

    HINT

     

    题意

    有n个程序员,第i个程序员每行会有ai个bug,然后让你按着顺序安排程序员,问你有多少种安排方法,可以使得写m行的bug最多b个

    题解:

    简单dp,dp[i][j]表示写i行bug数有j个的方法数

    转移方程和背包问题类似

    最后扫一遍统计一下就好

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 1000001
    #define eps 1e-9
    int Num;
    char CH[20];
    //const int inf=0x7fffffff;   //нчоч╢С
    const int inf=0x3f3f3f3f;
    /*
    
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    */
    inline ll read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    inline void P(int x)
    {
        Num=0;if(!x){putchar('0');puts("");return;}
        while(x>0)CH[++Num]=x%10,x/=10;
        while(Num)putchar(CH[Num--]+48);
        puts("");
    }
    //**************************************************************************************
    
    int dp[1000][1000];
    int main()
    {
        int n=read(),m=read(),b=read(),mod=read();
        dp[0][0]=1;
        for(int i=1;i<=n;i++)
        {
            int x=read();
            for(int j=1;j<=m;j++)
                for(int t=x;t<=b;t++)
                    dp[j][t]=(dp[j][t]+dp[j-1][t-x])%mod;
        }
        int ans=0;
        for(int i=0;i<=b;i++)
            ans=(ans+dp[m][i])%mod;
        cout<<ans<<endl;
    }
    C. Writing Code
  • 相关阅读:
    如何成为强大的程序员?(转)
    PHP Directory 函数
    PHP 类相关函数
    myeclipse安装svn插件的多种方式
    PHPEXCEL类操作EXCEL
    PHP 自定义错误处理函数(转)
    JBoss JBPM 实践系列(一) 安装配置(Tomcat 6.0 + MySQL 5.1)
    Ext.data.Store的相关知识
    Lotus Notes 和 Crystal Report 的整合應用
    JBoss JBPM 实践系列(二) jbpm设计器的配置和使用
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4487370.html
Copyright © 2020-2023  润新知