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 ...
随机推荐
- 流媒体技术学习笔记之(八)海康、大华IpCamera RTSP地址和格式
海康: rtsp://[username]:[password]@[ip]:[port]/[codec]/[channel]/[subtype]/av_stream 说明: username: 用户名 ...
- Spring RedisTemplate操作-List操作(4)
@Autowired @Resource(name="redisTemplate") private RedisTemplate<String, String> rt; ...
- js 语法高亮插件之 Prism.js
之前也介绍过几款语法高亮插件<为博客园选择一个小巧霸气的语法高亮插件>以及关于他们的综合性能<再议 语法高亮插件的选择>.今天在小影志博客看到<使用 Prism.js 实 ...
- MFC里ON_COMMAND_RANGE消息映射的ID问题
今天在工作中遇到一个问题,一个动态菜单,每个菜单的菜单项ID是我自己定义的,定义如下: #define IDM_SEARCHRECORD0 222240 #define IDM_SEARCHRECOR ...
- py-faster-rcnn代码阅读2-config.py
简介 该文件指定了用于fast rcnn训练的默认config选项,不能随意更改,如需更改,应当用yaml再写一个config_file,然后使用cfg_from_file(filename)导入以 ...
- imperva—waf 敏感字段显现
imperva WAF中看到的日志内容信息有些都是敏感的 比如登录登出的信息 如何调整敏感信息的现实方式,并可以自定义敏感字段? 这里添加字段就可以了 这样就将******转变为明文了
- 在Windows环境中利用Responder工具窃取NTLMv2哈希
在Windows环境中利用Responder工具窃取NTLMv2哈希 翻译自:https://github.com/incredibleindishell/Windows-AD-environment ...
- usb device address error 110
ubuntu失灵了,怎么都起不来,报一堆错误usb device descriptor read/64, error 110......重启,换kvm的接口,usb键盘鼠标...终于在试了下面这个方法 ...
- 在SharePoint 2013里配置Excel Services
配置步骤,请参看下面两篇文章 http://www.cnblogs.com/jianyus/p/3326304.html https://technet.microsoft.com/zh-cn/lib ...
- 通过 EXPLAIN 分析低效 SQL 的执行计划
每个列的简单解释如下: select_type:表示 SELECT 的类型,常见的取值有 SIMPLE(简单表,即不使用表连接 或者子查询).PRIMARY(主查询,即外层的查询).UNION(U ...