标签:
Description
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:
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: 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
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
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 }
codechef May Challenge 2016 CHSC: Che and ig Soccer dfs处理
标签:
原文地址:http://www.cnblogs.com/hsd-/p/5667358.html