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$,就代表这个字符 ...
随机推荐
- Spark Mllib框架1
1. 概述 1.1 功能 MLlib是Spark的机器学习(machine learing)库,其目标是使得机器学习的使用更加方便和简单,其具有如下功能: ML算法:常用的学习算法,包括分类.回归.聚 ...
- h5drag事件
在拖动目标上触发事件 (源元素):ondragstart - 用户开始拖动元素时触发ondrag - 元素正在拖动时触发ondragend - 用户完成元素拖动后触发释放目标时触发的事件:ondrag ...
- vue :class的动态绑定
动态绑定class 写在指令中的值会被视作表达式,如javascript表达式,因此v-bind:class接受三目运算: 1 2 3 4 HTML代码: <div :class=" ...
- Java Runtime 详解
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt219 那就首先说点Runtime类吧,他是一个与JVM运行时环境有关的类,这 ...
- [置顶]
基于FPGA的VGA简易显存设计&NIOS ii软核接入
项目简介 本项目基于Altera公司的Cyclone IV型芯片,利用NIOS II软核,2-port RAM与时序控制模块,实现64*48分辨率的显存(再大的显存板载资源m9k不够用) 实现效果如下 ...
- [转载]在instagram上面如何利用电脑来上传图片
原文地址:在instagram上面如何利用电脑来上传图片作者:小北的梦呓 我们都知道instagram是一个手机版的app,instagram官方不支持通过电脑来上传图片,而利用手机又很麻烦,那么如果 ...
- 转:【深入Java虚拟机】之三:类初始化
转载请注明出处:http://blog.csdn.net/ns_code/article/details/17845821 类初始化是类加载过程的最后一个阶段,到初始化阶段,才真正开始执行类中的Jav ...
- 201521123022 《Java程序设计》 第五周学习总结
1. 本周学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. 2. 书面作业 1.代码阅读:Child压缩包内源代码 1.1 com.parent包中Child.java文件能否编译通过? ...
- 201521123069 《Java程序设计》第1周学习总结
1. 本章学习总结 Java语言的发展.特点(面向对象.简单性.平台无关性) 认识并区分JVM(Java虚拟机),JRE(Java执行环境),JDK(Java开发工具包) 安装好JDK,设置Path变 ...
- Java课程设计--GUI密码生成器201521123033
1.团队课程设计题目 基于GUI的密码生成器 团队博客链接 2.个人负责模块 (1)界面设计 (2)部分错误输入的提示 (3)一键复制密码功能的实现 3.个人代码的提交记录截图 4.个人代码展示以及代 ...