codechef May Challenge 2016 CHSC: Che and ig Soccer dfs处理
Description
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 modulo 109 + 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.
Hint
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.9.2, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYPY, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM chicken, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#define ll long long
using namespace std;
int t;
int n,m,s;
int mov[];
int ans[];
void dfs(int pos ,int step)
{
if(step==m+)
{
ans[pos]++;
return ;
}
if((pos+mov[step])<=n)
{
dfs(pos+mov[step],step+);
}
if((pos-mov[step])>=)
dfs(pos-mov[step],step+);
}
int main()
{
while(scanf("%d",&t)!=EOF)
{
for(int i=;i<=t;i++)
{
memset(ans,,sizeof(ans));
memset(mov,,sizeof(mov));
scanf("%d %d %d",&n,&m,&s);
for(int j=;j<=m;j++)
scanf("%d",&mov[j]);
dfs(s,);
cout<<ans[];
for(int k=;k<=n;k++)
cout<<" "<<ans[k];
cout<<endl;
}
}
return ;
}
codechef May Challenge 2016 CHSC: Che and ig Soccer dfs处理的更多相关文章
- codechef May Challenge 2016 LADDU: Ladd 模拟
All submissions for this problem are available. Read problems statements in Mandarin Chinese, Russia ...
- codechef May Challenge 2016 FORESTGA: Forest Gathering 二分
Description All submissions for this problem are available. Read problems statements in Mandarin Chi ...
- Codechef April Challenge 2019 游记
Codechef April Challenge 2019 游记 Subtree Removal 题目大意: 一棵\(n(n\le10^5)\)个结点的有根树,每个结点有一个权值\(w_i(|w_i\ ...
- Codechef October Challenge 2018 游记
Codechef October Challenge 2018 游记 CHSERVE - Chef and Serves 题目大意: 乒乓球比赛中,双方每累计得两分就会交换一次发球权. 不过,大厨和小 ...
- Codechef September Challenge 2018 游记
Codechef September Challenge 2018 游记 Magician versus Chef 题目大意: 有一排\(n(n\le10^5)\)个格子,一开始硬币在第\(x\)个格 ...
- codechef February Challenge 2018 简要题解
比赛链接:https://www.codechef.com/FEB18,题面和提交记录是公开的,这里就不再贴了 Chef And His Characters 模拟题 Chef And The Pat ...
- Codechef November Challenge 2019 Division 1
Preface 这场CC好难的说,后面的都不会做QAQ 还因为不会三进制位运算卷积被曲明姐姐欺负了,我真是太菜了QAQ PS:最后还是狗上了六星的说,期待两(三)场之内可以上七星 Physical E ...
- codechef January Challenge 2014 Sereja and Graph
题目链接:http://www.codechef.com/JAN14/problems/SEAGRP [题意] 给n个点,m条边的无向图,判断是否有一种删边方案使得每个点的度恰好为1. [分析] 从结 ...
- Codechef March Challenge 2014——The Street
The Street Problem Code: STREETTA https://www.codechef.com/problems/STREETTA Submit Tweet All submis ...
随机推荐
- java程序换图标
ImageIcon img = new ImageIcon("D:\\mahou-in-action\\ShiJuanFenXi\\src\\zoom-in.png"); inst ...
- AngularJS 数组
AngularJS数组就像Javascript数组 <!DOCTYPE html><html><head><meta http-equiv="Con ...
- let和const在es6中的异同点
let和const这两个都是声明一个变量或函数的方法与var差不太多的效果 let的声明在for循环中,当你定义的是多少,最后你的值就是多少开始的,它只进行一次循环,不会像var那样去一遍一遍的去遍历 ...
- 学习笔记(六): Regularization for Simplicity
目录 Overcrossing? L₂ Regularization Lambda Examining L2 regularization Check Understanding Glossay Ov ...
- Centos7之WEB服务器
1.安装httpd服务 输入命令:yum -y install httpd [root@N37012 ~]# yum -y install httpc Loaded plugins: fastestm ...
- 一次完整的HTTP请求需要的7个步骤
HTTP通信机制是在一次完整的HTTP通信过程中,Web浏览器与Web服务器之间将完成下列7个步骤: 1:建立TCP连接 在HTTP工作开始之前,Web浏览器首先要通过网络与Web服务器建立连接,该连 ...
- 企业shell面试题及解答
1.面试题:使用for循环在/tmp目录下批量创建10个html文件,其中每个文件需要包含10个随机小写字母加固定字符串template,示例如下 aaesdffbnv_template.html 方 ...
- RPC框架 - thrift 服务端
-------服务端程序 ------ 下载 下载 thrift 源代码包 下载 thrift 的bin包 准备描述文件(使用源代码包的示例文件) \thrift-0.10.0\tu ...
- yii2初步讲解 验证规则
http://www.yii-china.com/post/detail/9.html
- Broken robot CodeForces - 24D (概率DP)
You received as a gift a very clever robot walking on a rectangular board. Unfortunately, you unders ...