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基础编程——用两个栈来实现一个队列
题目描述 用两个栈来实现一个队列,完成队列的Push和Pop操作. 队列中的元素为int类型. 题目代码 /** * <分析>: * 入队:将元素进栈A * 出队:判断栈B是否为空, * ...
- XGBoost算法原理小结
在两年半之前作过梯度提升树(GBDT)原理小结,但是对GBDT的算法库XGBoost没有单独拿出来分析.虽然XGBoost是GBDT的一种高效实现,但是里面也加入了很多独有的思路和方法,值得单独讲一讲 ...
- 洛谷P1481 魔族密码(LIS)
题意 题目链接 给出一堆字符串,若一个串是另一个串的前缀 ,那么它们可以连接在一起 问最大的链接长度 Sol LIS沙比提其实是做完了才看出是LIS #include<cstdio> #i ...
- linux替换yum源及配置本地源
linux系统安装后自带的bash源由于在国外,安装软件包的时候会非常慢,最好替换一下yum源. 关于yum源的简单介绍 yum的主要功能是更方便地添加,删除和更新rpmba ...
- 项目10.2-企业级自动化运维工具---puppet详解
1.认识puppet 1.1 引入 puppet是什么,咱们先不用专业的名词解释它,咱们先描述一些工作场景,看明白这些工作场景,自然会知道puppet是什么. (1)场景一: 管理员想要在100台服务 ...
- MySQL-Xtrabackup备份还原
前言 通常我们都是使用xtrabackup工具来备份数据库,它是一个专业的备份工具,先来简单介绍下它. Xtrabackup percona提供的mysql数据库备份工具,惟一开源的能够对innodb ...
- vue.js 发布后路径引用问题
在发布到iis目录下时候,如果放在网站的根目录下的时候,是不会有什么问题的 但是一旦放在了非根目录的其他文件夹里面,这时候index.html里引用的js和css文件路径都会找不到 错误如下 打开in ...
- webpack的配置处理
1.webpack对脚本的处理 1.Js用什么loader加载? 1>webpack 本身就支持js的加载, 2>通过babel-loader ES2015 加载js,再用 babel-p ...
- Laravel 命令行常用命令
一.简介 1.Artisan 是 Laravel 自带的命令行接口名称,它为我们在开发过程中提供了很多有用的命令.想要查看所有可用的Artisan命令,可使用list命令: php artisan l ...
- Django API 为 D3 提供数据
在工作中见过有的人即便使用了Django,依然还在采取json或geojson的文件形式为页面提供数据,相当于嵌入数据而非加载.下面是个简单有效的例子: 先从 model.py 开始 # models ...