http://codeforces.com/problemset/problem/712/D
2 seconds
512 megabytes
standard input
standard output
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.
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.
Print the number of possible games satisfying the conditions modulo 1 000 000 007 (109 + 7) in one line.
1 2 2 1
6
1 1 1 2
31
2 12 3 1
0
In the first sample test, Memory starts with 1 and Lexa starts with 2. If Lexa picks - 2, Memory can pick 0, 1, or 2 to win. If Lexa picks - 1, Memory can pick 1 or 2 to win. If Lexa picks 0, Memory can pick 2 to win. If Lexa picks 1 or 2, Memory cannot win. Thus, there are3 + 2 + 1 = 6 possible games in which Memory wins.
题意:两个人最开始有a,b两个初始数,玩t轮游戏,每个人都随机从【-k,k】之间获得一个数加进他们的分数,问最后问最开始是a的人比另外一个大的方案数%1e9就可以;
题解:f[i]表示得分为i的情况数(每轮更新),然后用sum[]来维护f[i]的前缀和,状态转移方程就是f[j]=(sum[loc]-sum[j-k-1]+mod)%mod;(loc=min(j+k,r-k)注意边界)

然后就是数组下表不能小于0;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long
double eps=1e-;
const int maxn=4e5+;
int zero=2e5+;
const int mod=1e9+;
using namespace std;
int f[maxn],sum[maxn];
int a,b,k,t;
int main()
{
scanf("%d %d %d %d",&a,&b,&k,&t);
int l=zero-k,r=zero+k;
//if(a==1&&b==100&&k==1000&&t==100)
for(int i=l;i<=r;i++)
{
f[i]=;
sum[i]=sum[i-]+f[i];
}
for(int i=;i<=t;i++)
{
l=zero-k*i,r=zero+k*i;
for(int j=l;j<=r;j++)
{
int loc=min(j+k,r-k);
f[j]=(sum[loc]-sum[j-k-]+mod)%mod;
}
for(int j=l;j<=r;j++)
{
sum[j]=(sum[j-]+f[j])%mod;
}
}
l=zero-t*k; r=zero+t*k;
int ans=;
for(int i=l;i<=r;i++)
{
int loc=min(i+a-b-,r);
ans=(ans+((ll)sum[loc]*f[i])%mod)%mod;
}
printf("%d\n",ans); }
http://codeforces.com/problemset/problem/712/D的更多相关文章
- http://codeforces.com/problemset/problem/594/A
A. Warrior and Archer time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- codeforces.com/problemset/problem/213/C
虽然一开始就觉得从右下角左上角直接dp2次是不行的,后面还是这么写了WA了 两次最大的并不一定是最大的,这个虽然一眼就能看出,第一次可能会影响第二次让第二次太小. 这是原因. 5 4 32 1 18 ...
- http://codeforces.com/problemset/problem/847/E
E. Packmen time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- http://codeforces.com/problemset/problem/545/D
D. Queue time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- codeforces 340C Tourist Problem
link:http://codeforces.com/problemset/problem/340/C 开始一点也没思路,赛后看别人写的代码那么短,可是不知道怎么推出来的啊! 后来明白了. 首先考虑第 ...
- codeforces B. Routine Problem 解题报告
题目链接:http://codeforces.com/problemset/problem/337/B 看到这个题目,觉得特别有意思,因为有熟悉的图片(看过的一部电影).接着让我很意外的是,在纸上比划 ...
- Codeforces 527D Clique Problem
http://codeforces.com/problemset/problem/527/D 题意:给出一些点的xi和wi,当|xi−xj|≥wi+wj的时候,两点间存在一条边,找出一个最大的集合,集 ...
- Codeforces 706C - Hard problem - [DP]
题目链接:https://codeforces.com/problemset/problem/706/C 题意: 给出 $n$ 个字符串,对于第 $i$ 个字符串,你可以选择花费 $c_i$ 来将它整 ...
- Codeforces 1096D - Easy Problem - [DP]
题目链接:http://codeforces.com/problemset/problem/1096/D 题意: 给出一个小写字母组成的字符串,如果该字符串的某个子序列为 $hard$,就代表这个字符 ...
随机推荐
- C++中值传递、指针传递、引用传递的总结
C++中值传递.指针传递.引用传递的总结 指针传递和引用传递一般适用于:函数内部修改参数并且希望改动影响调用者.对比值传递,指针/引用传递可以将改变由形参"传给"实参(实际上就 ...
- [js高手之路]深入浅出webpack教程系列6-插件使用之html-webpack-plugin配置(下)
上文我们对html-webpack-plugin的实例htmlWebpackPlugin进行了遍历分析,讲解了几个常用属性( inject, minify )以及自定义属性的添加,本文,我们继续深入他 ...
- 所有做java开发的都是些垃圾
所有做java开发的都是些垃圾,再垃圾的框架,只要有人用,对java程序员来说那就是高性能,高可用,解耦的,非常优秀的一款框架.属于吃屎都吃的津津有味.java里的框架都是垃圾,连一个不错的都没有.比 ...
- java 得到以后的日期
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt222 import java.text.ParseException; im ...
- Linux下的I/O模型以及各自的优缺点
其实关于这方面的知识,我阅读的是<UNIX网络编程:卷一>,书里是以UNIX为中心展开描述的,根据这部分知识,在网上参考了部分资料.以Linux为中心整理了这篇博客. Linux的I/O模 ...
- 浏览器console的用法
Leo_wlCnBlogs 自由.创新.研究.探索 Linux/Windows Mono/DotNet [ Open Source .NET Development/ 使用开源工具进行DotNet软件 ...
- 团队作业8——第二次项目冲刺(Beta阶段)5.21
1.当天站立式会议照片 会议内容: 本次会议为第三次会议 本次会议在陆大楼2楼召开,本次会议内容: ①:检查总结第二次任务完成情况 ②:布置第三次任务的详细分工 ③:规定完成时间是在第四次任务之前 ④ ...
- 团队作业4---第一次项目冲刺(AIpha版本)第二天
一.Daily Scrum Meeting照片 二.燃尽图 三.项目进展 1.界面 完成了主页及登录页面 2.功能 完成了后端数据处理的全部基本功能:a.数据结构设计及数据交互操作 b.博客页面数据采 ...
- 201521123074 《Java程序设计》第7周学习总结
1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. (嗯..都画了那么久的导图,还是用导图归纳吧~) 2. 书面作业 ArrayList代码分析 1.1 解释ArrayList ...
- 201521123004《Java程序设计》第6周学习总结
1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 注1:关键词与内容不求多,但概念之间的联系要清晰,内容覆盖 ...