CodeChef CHEFSOC2 Chef and Big Soccer 水dp

Chef and Big Soccer 

 
Problem code:  CHEFSOC2

All submissions for this problem are available.

Read problems statements in Mandarin ChineseRussian 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 A1A2, ..., 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+10,M=1e6+10,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,0,sizeof(dp));
        dp[0][s]=1;
        for(i=1;i<=m;i++)
        scanf("%d",&a[i]);
        for(i=1;i<=m;i++)
        {
            for(t=1;t<=n;t++)
            {
                int zuo=t-a[i];
                int you=t+a[i];
                if(zuo>0&&zuo<=n)
                dp[i][t]+=dp[i-1][zuo];
                if(you>0&&you<=n)
                dp[i][t]+=dp[i-1][you];
                dp[i][t]%=mod;
            }
        }
        for(i=1;i<=n;i++)
        {
            printf("%lld%c",dp[m][i],(i!=n)?' ':'\n');
        }
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/jhz033/p/5669465.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值