codeforces 544C(完全背包求方案数)
题意描述
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 a i bugs in every line of code that he writes.
Let’s call a sequence of non-negative integers v 1, v 2, …, v n a plan, if v 1 + v 2 + … + v n = m. The programmers follow the plan like that: in the beginning the first programmer writes the first v 1 lines of the given task, then the second programmer writes v 2 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.
第i个人写一行代码会出vi个bug,要求写m行代码,询问bug不超过b个的方案数
思路
由于每个人可以打多行代码,所以很明显的可以想到这是一道完全背包,所以可以用f[i][j]表示前i行代码bug不超过j个的方案的集合,由于要求的是方案数,所以我们知道两个状态间的计算方式肯定是相加的。从而得到状态转移方程:
其余套用完全背包模板即可
AC代码
#include<bits/stdc++.h>
#define x first
#define y second
#define PB push_back
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) begin(a),end(a)
#define rep(x,l,u) for(ll x=l;x<u;x++)
#define rrep(x,l,u) for(ll x=l;x>=u;x--)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;
typedef pair<char,char> PCC;
typedef long long ll;
const int N=505;
ll a[N],f[N][N];
void solve(){
int n,m,b,mod;cin>>n>>m>>b>>mod;
rep(i,1,n+1) cin>>a[i];
f[0][0]=1;
rep(i,1,n+1){
rep(j,1,m+1){
rep(k,a[i],b+1){
f[j][k]=(f[j][k]+f[j-1][k-a[i]])%mod;
}
}
}
ll sum=0;
rep(i,0,b+1) sum=(sum+f[m][i])%mod;
cout<<sum<<endl;
}
int main(){
IOS;
solve();
return 0;
}
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- ModuleNotFoundError: No module named ‘pip‘【已解决】
- 【原创】Java并发编程系列31 | 阻塞队列(上)
- 【2019-3-3】Mac启动redis
- awvs(acunetix)使用一段时间后突然不能用了-解决方案
- Java自动化测试(数据库断言 18)
- Java自动化测试(参数化 19)
- Python 基础(一):入门必备知识
- Mac安装软件提示 已损坏【已解决】
- 机器学习之sklearn基础教程!
- 2020最新版 maven for MAC 安装及配置
- jemter安装(win/mac)并快捷启动的方法
- nmap 详解版-指令使用方法大全【含安装】
- 常见6种WAF绕过和防护原理
- 2020-mac 安装jdk1.8
- AWVS acunetix_WVS13的基础使用