Codeforces Round #302 (Div. 1) A. Writing Code
来源:互联网 发布:全民突击刷枪内购软件 编辑:程序博客网 时间:2024/06/05 06:52
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.
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.
Print a single integer — the answer to the problem modulo mod.
3 3 3 1001 1 1
10
3 6 5 10000000071 2 3
0
3 5 6 111 2 1
0
dp问题
设dp[i][j]表示把i分解成j的种数,则每当加入一个pri[i],dp[i][j] = sum{dp[i-pri[i]][j-1]},相当于背包问题一样,一个物品可以多次累加,故从j-1
可推出!
#include "stdafx.h"#include "stdio.h"#include "string.h"#include "math.h"#include <algorithm>#include <vector>#include <queue>#include <iostream>using namespace std;#define N 505#define SCANF scanf_sint dp[N][N];int pri[N];int main(){int n,m,b,mod;bool isEnd;while (SCANF("%d%d%d%d", &n,&m,&b,&mod) != EOF){memset(dp, 0, sizeof(dp));for (int i = 1; i <= n; i++){SCANF("%d",&pri[i]);}for (int i = 0; i <= b;i++)for (int j = 0; j <= m; j++){dp[i][j] = dp[i][j] = 0;}dp[0][0] = 1;int flag = 1;for (int i = 1; i <= n; i++){for (int j = pri[i]; j <= b ; j++){for (int k = 1; k <= m; k++){dp[j][k]= (dp[j][k] + dp[j - pri[i]][k - 1]) % mod;}}}int ans = 0;for (int i = 0; i <= b; i++){ans =(ans + dp[i][m])%mod;}cout << ans << endl;}return 0;}
- Codeforces Round #302 (Div. 1) A. Writing Code
- Codeforces Round #302 (Div. 1) 543A Writing Code(dp)
- Codeforces Round #302 (Div. 2) A.Set of Strings&B.Sea and Islands&C.Writing Code
- Codeforces Round #302 (Div. 2)C. Writing Code--dp
- Codeforces Round #302 (Div. 2) C. Writing Code dp
- Codeforces Round #302 (Div. 2)-C. Writing Code
- 完全背包——Codeforces Round #302 (Div. 2) C. Writing Code
- CodeForces 543A-Writing Code
- C. Writing Code(Codeforces Round #302(div2)
- Writing Code - CodeForces 543 A dp
- Codeforces 543A. Writing Code DP
- CodeForces 543A Writing Code(DP)
- codeforces 543A Writing Code (dp)
- [CodeForces 543A]Writing Code[DP]
- Codeforces 543 A Writing Code 计数DP
- Codeforces 543A. Writing Code DP
- Codeforces Round #202 (Div. 1) A. Mafia
- Codeforces Round #212 (Div. 1) <A>
- 短信发送器的实现
- 黑马程序员-----Java基础-----I/O流操作
- 子类继承父类的私有属性
- 关于王垠和Lisp的感悟
- 求最大子数组的和(动态规划法)
- Codeforces Round #302 (Div. 1) A. Writing Code
- 总结自己的Git常用命令
- android的单元调试
- 欢迎使用CSDN-markdown编辑器
- ios给NSMutableDictionary循环赋值的两种方式,在循环内初始化NSMutableDictionary和在循环外初始化NSMutableDictionary有何区别?(已解决)
- 545B Equidistant string
- 文件存储的实现-login登录案例3-SharedPreferences
- struts1.2 几种Action详解
- toj 1528 Least Common Multiple