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

  • 1T10
  • 1N, M10^3
  • 1sN
  • 1Ai10^3

Subtasks

  • Subtask #1 (30 points) : N, M10
  • 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

Source Limit: 50000
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

题意:中文题面   https://s3.amazonaws.com/codechef_shared/download/translated/MAY16/mandarin/CHEFSOC2.pdf

题解: 一个变形的数塔问题 简单dfs处理.

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<set>
 5 #define ll  long long
 6 using namespace std;
 7 int t;
 8 int n,m,s;
 9 int mov[1005];
10 int ans[1005];
11 void dfs(int pos ,int step)
12 {
13     if(step==m+1)
14         {
15             ans[pos]++;
16             return ;
17         }
18     if((pos+mov[step])<=n)
19     {
20         dfs(pos+mov[step],step+1);
21     }
22     if((pos-mov[step])>=1)
23         dfs(pos-mov[step],step+1);
24 }
25 int main()
26 {
27     while(scanf("%d",&t)!=EOF)
28     {
29         for(int i=1;i<=t;i++)
30     {
31         memset(ans,0,sizeof(ans));
32         memset(mov,0,sizeof(mov));
33         scanf("%d %d %d",&n,&m,&s);
34         for(int j=1;j<=m;j++)
35          scanf("%d",&mov[j]);
36          dfs(s,1);
37         cout<<ans[1];
38         for(int k=2;k<=n;k++)
39             cout<<" "<<ans[k];
40         cout<<endl;
41     }
42     }
43     return 0;
44 }
时间: 2024-12-29 07:26:40

codechef May Challenge 2016 CHSC: Che and ig Soccer dfs处理的相关文章

codechef May Challenge 2016 FORESTGA: Forest Gathering 二分

Description All submissions for this problem are available. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is the head of commercial logging industry that recently bought a farm containing N trees. You are given in

Codechef July Challenge 2014部分题解

Dish Owner(并查集) 链接:http://www.codechef.com/JULY14/problems/DISHOWN/ 题意分析:本题主要操作就是给出0 x y时,拥有第x道菜的厨师与拥有第y道菜的厨师pk,谁拥有的所有菜的其中一道菜(不一定是x或y)的分值比较高谁就获胜,并赢得loser的所有菜.即比较的是每个人分值最高的菜,所以对于非loser的人来说,他的分值最高的菜是不变的.综合题意用并查集易解. #include <cstdio> const int Maxn=100

Codechef October Challenge 2018 游记

Codechef October Challenge 2018 游记 CHSERVE - Chef and Serves 题目大意: 乒乓球比赛中,双方每累计得两分就会交换一次发球权. 不过,大厨和小厨用了另外一种规则:双方每累计得 K 分才会交换发球权.比赛开始时,由大厨发球. 给定大厨和小厨的当前得分(分别记为 P1 和 P2),请求出接下来由谁发球. 思路: \((P1+P2)\%K\)判断奇偶性即可. 代码链接 BITOBYT - Byte to Bit 题目大意: 在字节国里有三类居民

Maximum number, GCD condition (codechef March Challenge 2014)

题目 : http://acm.bnu.edu.cn/v3/problem_show.php?pid=40489 最近做到的一道蛮有意思的题目(codechef现在的题目确实很赞了) 题意 :中文题面 (cc的一大好处就是有中文翻译,嘿嘿) 区间Max = max{a_i|gcd(a_i, g) > 1 && x <= i <= y} 做法 : 一开始我是用分块做的,复杂的O(m * sqrt(n) * C) C 是所含不同素数的个数, C大概最大只有6或7吧 然后裸裸的

Codechef March Challenge 2014——The Street

The Street Problem Code: STREETTA https://www.codechef.com/problems/STREETTA Submit Tweet All submissions for this problem are available. Read problems statements in Mandarin Chineseand Russian. The String street is known as the busiest street in Cod

CF&amp;&amp;CC百套计划2 CodeChef December Challenge 2017 Chef And his Cake

https://www.codechef.com/DEC17/problems/GIT01 #include<cstdio> #include<algorithm> using namespace std; #define N 101 char s[N]; int main() { int T; scanf("%d",&T); int n,m; int OddG,OddR,EvenG,EvenR; int ans; while(T--) { OddG=O

CF&amp;&amp;CC百套计划2 CodeChef December Challenge 2017 Chef and Hamming Distance of arrays

https://www.codechef.com/DEC17/problems/CHEFHAM #include<cstdio> #include<cstring> #include<iostream> using namespace std; #define N 100001 int a[N],b[N]; int sum[N],wh[N][2]; int num1[N],num2[N]; void read(int &x) { x=0; char c=getc

CF&amp;&amp;CC百套计划2 CodeChef December Challenge 2017 Total Diamonds

https://www.codechef.com/DEC17/problems/VK18 #include<cstdio> #include<iostream> #include<algorithm> using namespace std; #define N 1000001 long long sum[N*2],dp[N]; int num[11]; void read(int &x) { x=0; char c=getchar(); while(!isdi

CF&amp;&amp;CC百套计划2 CodeChef December Challenge 2017 Penalty Shoot-out

https://www.codechef.com/DEC17/problems/CPLAY #include<cstdio> #include<algorithm> using namespace std; char s[21]; int main() { int sumA,sumB; while(scanf("%s",s+1)!=EOF) { sumA=sumB=0; int i; for(i=1;i<=10;++i) { if(i&1) { i