codeforces Gym 101102A
来源:互联网 发布:灵魂摆渡类似的网络剧 编辑:程序博客网 时间:2024/05/22 13:31
这个就是背包,背包专题做少了,再来20道吧,这是约旦的比赛
dp还是弱啊。。。。
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long LL;const int MaxN = 15000 + 10;const int mol = 1e9 + 7;LL a[MaxN] , b[MaxN] , f[MaxN] , g[MaxN];int t , n , m , k , w;void pdo(){ memset(f , 0 , sizeof(f)); memset(g , 0 , sizeof(g)); f[0] = (LL)1;//这个是这么回事,0为一种方案 for(int i = 0 ; i < n ; i++){ for(int j = w ; j >= a[i] ; j--){//选取a f[j] = (f[j] + f[j - a[i]])%mol;//这个是这么回事, } } g[0] = (LL)1;//0,为一种方案 for(int i = 0 ; i < m ; i++){ for(int j = w ; j >= b[i] ; j--){//选取b g[j] = (g[j] + g[j - b[i]])%mol;//j为钱数,还有算b[i]钱数 } } LL ans = 0; for(int i = 0 ; i <= w ; i++){ if(abs(i - (w - i)) <= k){//判断小于k ans = (ans + g[i] * f[w - i])%mol;//然后g,f,符合条件相乘 } } printf("%d\n",ans);}int main(){ scanf("%d",&t); while(t--){ scanf("%d %d %d %d",&n ,&m ,&k ,&w); for(int i = 0 ; i < n ; i++) scanf("%d",&a[i]); for(int i = 0 ; i < m ; i++) scanf("%d",&b[i]); pdo(); }}
0 0
- codeforces Gym 101102A
- Codeforces gym 101102 A dp
- codeforces gym 100645A
- CodeForces Gym 100803A
- Codeforces Gym 100372A
- 【Codeforces Gym 100187A】
- Codeforces Gym 100340A Cookies
- codeforces gym 100827A Runes
- Codeforces GYM 100340A Cookies
- Codeforces gym 101343 A 数论
- Codeforces gym 101350A dp
- Codeforces Rating Gym-101028A
- codeforces Gym 101102F
- Codeforces Gym 100889 A. A Beautiful Array
- CodeForces Gym 100989A LCS (A)
- Codeforces Gym 101158 A. Rearranging a Sequence
- Codeforces Gym 100345A BibTeX 模拟
- codeforces Gym 100187 A. Potion of Immortality
- 欢迎使用CSDN-markdown编辑器
- php定时执行
- Python内置函数学习(1)-abs(x)
- 习题
- php opcode缓存
- codeforces Gym 101102A
- 关于RecycleView用法的个人浅解
- 《go语言编程》学习笔记一
- Lightoj1011【KM算法】
- ThinkPHP无法自动生成表单令牌问题
- [Linux C编程]进程控制编程
- 洛谷 P1731 [NOI1999 D1T3] 生日蛋糕
- 什么是字节对齐,为什么要字节对齐?
- 第十二天