zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    利用Js/Jquery实现div的隐藏与显示(注意释放与不释放空间)
    关于js 中 alert 事件弹框提示,title显示页面url网址问题
    前端获取Ajax请求获取数据,无法赋值给全局变量
    JS根据条件正则截取相应字符,以及常用截取函数
    Git切换分支命令
    CodeIgniter (CI)框架中的数据库查询汇总
    解决Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)错误//解决 413 Request Entity Too Large
    Linux: cp 复制文件(文件夹)
    LeeCode(No4
    RSS简介
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4487370.html
Copyright © 2011-2022 走看看