CodeChef CHEFSOC2 Chef and Big Soccer 水dp
Chef and Big SoccerProblem code: CHEFSOC2
|
All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef is a big fan of soccer! He loves soccer so much, that he even invented soccer for his pet dogs! Here are the rules of the game:
- There are N dogs numerated from 1 to N stay in a line, so dogs i and i + 1 are adjacent.
- There is a ball which dogs will pass around. Initially, dog s has the ball.
- A dog with ball can pass it to another dog. If the current pass-strength of dog is x, then it can pass the ball to either dog i - x or dog i + x (provided such dog/s exist).
To make it even more exciting, Chef created an array A of M positive integers denoting pass strengths. In i-th pass, current pass-strength of the dog making the pass will be given by Ai.
Chef asks dogs to execute these M passes one by one. As stated before, dog s will make the first pass, then some other dog and so on till M passes.
Dogs quickly found out that there can be lot of possible sequences of passes which will end up with a dog having the ball. Now each dog asks your help in finding number of different pass sequences which result in this dog ending up ball. Two pass sequences are considered different if after some number of passes they lead the ball to different dogs. As the answer could be quite large, output it modulo 109 + 7 (1000000007).
Input
- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
- The first line of each test case contains three space separated integers N, M, s denoting the number of dogs, number of pass strengths and number of dog having a ball at the beginning.
- The second line contains M space-separated integers A1, A2, ..., AM denoting the pass strengths.
Output
- For each test case, output a single line containing N space-separated integers, where i-th integer should be equal to number of different valid pass sequences leading the ball to i-th dog modulo109 + 7.
Constraints
- 1 ≤ T ≤ 10
- 1 ≤ N, M ≤ 10^3
- 1 ≤ s ≤ N
- 1 ≤ Ai ≤ 10^3
Subtasks
- Subtask #1 (30 points) : N, M ≤ 10
- Subtask #2 (70 points) : Original constraints
Example
Input:
3
3 2 2
1 2
3 3 3
1 1 1
3 1 1
3 Output:
1 0 1
0 2 0
0 0 0
Explanation
Example case 1.
Possible sequence for dog 1 is 2->3->1.
Possible sequence for dog 3 is 2->1->3.
Example case 2.
Possible sequences for dog 2 are 3->2->1->2 and 3->2->3->2.
Example case 3.
There are no valid sequences for such input.
题意:n个人,m次传球,告诉你每次踢球的力度,起始在s处;
思路:dp[i][t]=dp[i-1][t-a[i]]+dp[i-1][t+a[i]];
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define esp 0.00000000001
const int N=2e3+,M=1e6+,inf=1e9;
int a[N];
int n,m,s;
ll dp[N][N];
int main()
{
int i,t;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&s);
memset(dp,,sizeof(dp));
dp[][s]=;
for(i=;i<=m;i++)
scanf("%d",&a[i]);
for(i=;i<=m;i++)
{
for(t=;t<=n;t++)
{
int zuo=t-a[i];
int you=t+a[i];
if(zuo>&&zuo<=n)
dp[i][t]+=dp[i-][zuo];
if(you>&&you<=n)
dp[i][t]+=dp[i-][you];
dp[i][t]%=mod;
}
}
for(i=;i<=n;i++)
{
printf("%lld%c",dp[m][i],(i!=n)?' ':'\n');
}
}
return ;
}
CodeChef CHEFSOC2 Chef and Big Soccer 水dp的更多相关文章
- CodeForces 706C Hard problem (水DP)
题意:对于给定的n个字符串,可以花费a[i] 将其倒序,问是否可以将其排成从大到小的字典序,且花费最小是多少. 析:很明显的水DP,如果不是水DP,我也不会做.... 这个就要二维,d[2][max ...
- 水dp第二天(背包有关)
水dp第二天(背包有关) 标签: dp poj_3624 题意:裸的01背包 注意:这种题要注意两个问题,一个是要看清楚数组要开的范围大小,然后考虑需要空间优化吗,还有事用int还是long long ...
- HDU 2084 数塔 (水DP)
题意:.... 析:从下往上算即可,水DP. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #incl ...
- [Codechef CHSTR] Chef and String - 后缀数组
[Codechef CHSTR] Chef and String Description 每次询问 \(S\) 的子串中,选出 \(k\) 个相同子串的方案有多少种. Solution 本题要求不是很 ...
- hdu 2571 命运(水DP)
题意: M*N的grid,每个格上有一个整数. 小明从左上角(1,1)打算走到右下角(M,N). 每次可以向下走一格,或向右走一格,或向右走到当前所在列的倍数的列的位置上.即:若当前位置是(i,j), ...
- Codechef December Challenge 2014 Chef and Apple Trees 水题
Chef and Apple Trees Chef loves to prepare delicious dishes. This time, Chef has decided to prepare ...
- CodeChef - CHEFPRAD Chef and Pairs 树形DP
题意 给你一棵由 N 个节点构成的树 T.节点按照 1 到 N 编号,每个节点要么是白色,要么是黑色.有 Q 组询问,每组询问形如 (s, b).你需要检查是否存在一个连通子图,其大小恰好是 s,并 ...
- CodeChef FAVNUM FavouriteNumbers(AC自动机+数位dp+二分答案)
All submissions for this problem are available. Chef likes numbers and number theory, we all know th ...
- Codechef FNCS Chef and Churu
Disciption Chef has recently learnt Function and Addition. He is too exited to teach this to his fri ...
随机推荐
- Centos6.5下DHCP服务器的安装和配置
1.首先需要安装DHCP的软件包,使用yum进行安装 # yum install -y dhcp.x86_64 dhcp-devel.x86_64 2.将/usr/share/doc/dhcp-4. ...
- ubuntu微信
方法1 – 使用Snap来安装微信 依次在terminal 执行一下命令 sudo apt install snapd snapd-xdg-open sudo snap install electro ...
- python split(),os.path.split()和os.path.splitext()函数用法
https://blog.csdn.net/T1243_3/article/details/80170006 # -*- coding:utf-8 -*- """ @ ...
- 接口测试工具 — jmeter(header与cookie的添加)
1.header的添加 添加HTTP信息头管理器 填写header 2.添加cookie 添加HTTP Cookie管理器 添加cookie值
- js事件委托和jQuery事件绑定on , off , one , bind , unbind , die
一. 事件委托什么是事件委托?用现实中的理解就是:有100 个学生同时在某天中午收到快递,但这100 个学生不可能同时站在学校门口等,那么都会委托门卫去收取,然后再逐个交给学生.而在jQuery 中, ...
- centos6.5关闭防火墙命令
1.永久性生效,重启后不会复原 开启: chkconfig iptables on 关闭: chkconfig iptables off 2.即时生效,重启后复原 开启: service iptabl ...
- 洛谷 P2331 [SCOI2005]最大子矩阵
洛谷 这一题,乍一眼看上去只想到了最暴力的暴力--大概\(n^4\)吧. 仔细看看数据范围,发现\(1 \leq m \leq 2\),这就好办了,分两类讨论. 我先打了\(m=1\)的情况,拿了30 ...
- pandas 修改列名
原始文件 下面是Excel打开以及pd.read_csv() 打开: 里面只是干巴巴的数据,没有列名,so,需要给其设置列名. Method1 不让第一行数据默认当作列名(默认第一行数据是列名了). ...
- ps如果换背景
一.魔棒工具 魔棒工具主要是使用户可以选择颜色一致的区域(例如,一朵红花)或者背景比较单调的图片,而不必跟踪其轮廓.魔棒工具选择的颜色范围可以由工具选项栏中的误差范围 参数值来控制. 二.钢笔工具 路 ...
- 全球第一张中文网络协议分析图——By 成都科来软件
网上内容比较全面的网络协议图并不是很多,这些网络协议图大多只遵循OSI,对于TCP/IP基本不支持,有些协议图表示也不够准确.另一方面,现在网上能找到的协议图全都是英文版本,使用起来不是很方便.国内的 ...