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$,就代表这个字符 ...
随机推荐
- 12块钱搭建一个ss(包括一个免费服务器)
AWS搭建ss(shadow socks) 如果你符合以下条件,那么继续看还是有点帮助的: 想搞个服务器(包括windows Linux)(免费) 想科学上网(也免费) 之前也从网上搜过本文内容,但手 ...
- 如何通过jmeter使用beanshell进行关联
关联,大多数都是通过响应的信息抓取部分信息,例如session或者hidden等 在jmeter中要使用关联,分为以下2步: Step 1. 在Sampler请求下添加正则表达式,获得信息,添加 &g ...
- Spark 1.6升级2.x防踩坑指南
原创文章,谢绝转载 Spark 2.x自2.0.0发布到目前的2.2.0已经有一年多的时间了,2.x宣称有诸多的性能改进,相信不少使用Spark的同学还停留在1.6.x或者更低的版本上,没有升级到2. ...
- 大型网站的 HTTPS 实践(二)——HTTPS 对性能的影响
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt388 HTTPS 在保护用户隐私,防止流量劫持方面发挥着非常关键的作用,但与 ...
- IOS学习【xcode 7新特性url链接】
由于xcode7的更新,在访问http链接的时候会输出错误信息 The resource could not be loaded because the App Transport Security ...
- 没有闲话和grunt.initConfig()
grunt.initConfig()为Gruntfile.js的核心部分,它接收对象作为参数. 对象包含两种类型的属性,一种是单纯的变量,一种是task类型.举个栗子: grunt.initConfi ...
- AmpLab Tachyon and Shark update
一个开源的文件系统,拿来主义,先收藏,用得到细品. 简介:https://www.youtube.com/watch?v=cAZ624-69PQ 官网:http://tachyon-project.o ...
- 201521123061 《Java程序设计》第十周学习总结
201521123061 <Java程序设计>第十周学习总结 1. 本周学习总结 1.这周异常方面的知识主要是关于自定义异常,自定义的异常可以继承自Throwable或Exception类 ...
- 201521123065《Java程序设计》第2周学习总结
1.本周学习总结 字符串创建后是不可变的,可以使用加号进行字符串之间的拼接. 使用for循环对字符串进行修正会不断产生新的字符串,应使用StringBuilder. 字符串内容的比较要用equal. ...
- Java补码表和位移运算符
在java中数据都是以二进制的形式保存的. 但是我们看到的数据怎么是10进制的? 因为java展示之前会自动调用toString()方法 这里以4位2进制为例,4位2进制只能表示16个数,即0-15. ...