Codeforces Round #370 (Div. 2) D. Memory and Scores 动态规划
D. Memory and Scores
题目连接:
http://codeforces.com/contest/712/problem/D
Description
Memory and his friend Lexa are competing to get higher score in one popular computer game. Memory starts with score a and Lexa starts with score b. In a single turn, both Memory and Lexa get some integer in the range [ - k;k] (i.e. one integer among - k, - k + 1, - k + 2, ..., - 2, - 1, 0, 1, 2, ..., k - 1, k) and add them to their current scores. The game has exactly t turns. Memory and Lexa, however, are not good at this game, so they both always get a random integer at their turn.
Memory wonders how many possible games exist such that he ends with a strictly higher score than Lexa. Two games are considered to be different if in at least one turn at least one player gets different score. There are (2k + 1)2t games in total. Since the answer can be very large, you should print it modulo 109 + 7. Please solve this problem for Memory.
Input
The first and only line of input contains the four integers a, b, k, and t (1 ≤ a, b ≤ 100, 1 ≤ k ≤ 1000, 1 ≤ t ≤ 100) — the amount Memory and Lexa start with, the number k, and the number of turns respectively.
Output
Print the number of possible games satisfying the conditions modulo 1 000 000 007 (109 + 7) in one line.
Sample Input
1 2 2 1
Sample Output
6
Hint
题意
有两个人在玩游戏,一开始分数分别为a和b,每一局,每个人可以获得分数[-k,k]之间,问你A胜过B的方案数有多少种
题解:
dp[i][j]表示第i轮之后,获得j分数的方案数。
显然这个只会和上一轮有关,所以可以滚动数组优化,又显然可以前缀和优化。
然后维护一下DP
最后再枚举A的分数,统计一下答案就好了。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 4e5+7;
const int le = 2e5;
const int mod = 1e9+7;
long long a,b,k,t;
long long dp[2][maxn];
long long sum[maxn];
int now=0,pre=1;
int main()
{
scanf("%lld%lld%lld%lld",&a,&b,&k,&t);
dp[now][le]=1;
for(int i=1;i<=t;i++)
{
for(int j=1;j<maxn;j++)
{
sum[j]=dp[now][j]+sum[j-1];
sum[j]%=mod;
}
swap(now,pre);
memset(dp[now],0,sizeof(dp[now]));
for(int j=1;j<maxn;j++)
{
dp[now][j]+=sum[min(maxn-1LL,j+k)]-sum[max(0LL,j-k-1)];
dp[now][j]%=mod;
}
}
for(int j=1;j<maxn;j++)
{
sum[j]=dp[now][j]+sum[j-1];
sum[j]%=mod;
}
long long ans = 0;
for(int j=0;j<maxn;j++)
{
ans += sum[a+j-b-1]%mod*dp[now][j]%mod;
ans%=mod;
}
cout<<(ans+mod)%mod<<endl;
}
Codeforces Round #370 (Div. 2) D. Memory and Scores 动态规划的更多相关文章
- Codeforces Round #370 (Div. 2) D. Memory and Scores DP
D. Memory and Scores Memory and his friend Lexa are competing to get higher score in one popular c ...
- Codeforces Round #370 (Div. 2) E. Memory and Casinos 线段树
E. Memory and Casinos 题目连接: http://codeforces.com/contest/712/problem/E Description There are n casi ...
- Codeforces Round #370 (Div. 2)C. Memory and De-Evolution 贪心
地址:http://codeforces.com/problemset/problem/712/C 题目: C. Memory and De-Evolution time limit per test ...
- Codeforces Round #370 (Div. 2)B. Memory and Trident
地址:http://codeforces.com/problemset/problem/712/B 题目: B. Memory and Trident time limit per test 2 se ...
- Codeforces Round #370 (Div. 2) C. Memory and De-Evolution 水题
C. Memory and De-Evolution 题目连接: http://codeforces.com/contest/712/problem/C Description Memory is n ...
- Codeforces Round #370 (Div. 2) B. Memory and Trident 水题
B. Memory and Trident 题目连接: http://codeforces.com/contest/712/problem/B Description Memory is perfor ...
- Codeforces Round #370 (Div. 2) A. Memory and Crow 水题
A. Memory and Crow 题目连接: http://codeforces.com/contest/712/problem/A Description There are n integer ...
- Codeforces Round #370 (Div. 2) E. Memory and Casinos (数学&&概率&&线段树)
题目链接: http://codeforces.com/contest/712/problem/E 题目大意: 一条直线上有n格,在第i格有pi的可能性向右走一格,1-pi的可能性向左走一格,有2中操 ...
- Codeforces Round #556 (Div. 2) - D. Three Religions(动态规划)
Problem Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 3000 mSec Problem Descripti ...
随机推荐
- Github 开源项目(二) jsmpeg-vnc
参考文章:http://blog.csdn.net/qq_28877125/article/details/70141713 适用于Windows的低延迟,高帧率屏幕共享服务器以及用于浏览器的客户端 ...
- 使用JWPL (Java Wikipedia Library)操作维基百科数据
使用JWPL (Java Wikipedia Library)操作维基百科数据 1. JWPL介绍 JWPL(Java Wikipedia Library)是一个开源的访问wikipeida数据的Ja ...
- 20155306 2016-2017-2 《Java程序设计》第八周学习总结
20155306 2016-2017-2 <Java程序设计>第八周学习总结 教材学习内容总结 第十五章 通用API 15.1 日志 java.util.loggging包提供了日志功能相 ...
- MySQL索引背后的数据结构及算法原理 (转)
摘要 本文以MySQL数据库为研究对象,讨论与数据库索引相关的一些话题.特别需要说明的是,MySQL支持诸多存储引擎,而各种存储引擎对索引的支持也各不相同,因此MySQL数据库支持多种索引类型,如BT ...
- 在xampp与phpstorm环境下安装xdebug[转]
XDebug是什么 很多PHP程序员调试使用echo.print_r().var_dump().printf()等,虽然对于有较丰富开发经验的程序员来说这些也已经足够了,他们往往可以在程序执行的过程中 ...
- linux中Shell标准输出错误 >/dev/null 2>&1 分析【转】
Shell中可能经常能看到:>/dev/null 2>&1 eg:sudo kill -9 `ps -elf |grep -v grep|grep $1|awk '{print ...
- springboot创建一个可执行的jar
让我们通过创建一个完全自包含的可执行jar文件来结束我们的示例,该jar文件可以在生产环境运行.可执行jars(有时候被成为胖jars "fat jars")是包含你的编译后的类和 ...
- KVM -> 虚拟化简介&虚拟机安装_01
什么是虚拟化? 在计算机技术中,虚拟化(技术)或虚拟技术(英语:Virtualization)是一种资源管理技术,是将计算机的各种实体资源(CPU.内存.磁盘空间.网络适配器等),予以抽象.转换后呈现 ...
- 20165203 Mypwd的解读与实现
20165203 Mypwd的解读与实现 pwd 含义:在Linux层次结构中,想要知道当前所处的目录,可以用pwd命令,该命令显示整个路径名. 语法:pwd [option] 描述:pwd 命令将当 ...
- yum源安装php报错缺少libmcrypt.so.4()(64bit)库
https://blog.csdn.net/programercch/article/details/56282184