codechef AUG17 T5 Chef And Fibonacci Array

Chef has an array A = (A1, A2, ..., AN), which has N integers in it initially. Chef found that for i ≥ 1, if Ai > 0, Ai+1 > 0, and Ai+2 exists, then he can decrease both Ai, andAi+1 by one and increase Ai+2 by one. If Ai+2 doesn‘t exist, but Ai > 0, and Ai+1 > 0, then he can decrease both Ai, and Ai+1 (which will be the currently last two elements of the array) by one and add a new element at the end, whose value is 1.

Now Chef wants to know the number of different arrays that he can make from A using this operation as many times as he wishes. Help him find this, and because the answer could be very large, he is fine with you reporting the answer modulo 109+7.

Two arrays are same if they have the same number of elements and if each corresponding element is the same. For example arrays (2,1,1) and (1,1,2) are different.

Input

  • The first line of the input contains a single integer T denoting the number of test cases.
  • The first line contains a single integer N denoting the initial number of elements inA.
  • The second line contains N space-separated integers: A1, A2, ... , AN.

Output

For each test case, output answer modulo 109+7 in a single line.

Constraints

  • 1 ≤ T ≤ 5
  • 1 ≤ N ≤ 50
  • 0 ≤ Ai ≤ 50

Subtasks

  • Subtask 1 (20 points) : 1 ≤ N ≤ 8, 0 ≤ Ai ≤ 4
  • Subtask 2 (80 points) : Original constraints

Example

Input:
3
3
2 3 1
2
2 2
3
1 2 3

Output:
9
4
9

Explanation

Example case 1.

We‘ll list the various single steps that you can take (ie. in one single usage of the operation):

  • (2, 3, 1) → (2, 2, 0, 1)
  • (2, 2, 0, 1) → (1, 1, 1, 1)
  • (1, 1, 1, 1) → (1, 1, 0, 0, 1)
  • (1, 1, 0, 0, 1) → (0, 0, 1, 0, 1)
  • (1, 1, 1, 1) → (1, 0, 0, 2)
  • (1, 1, 1, 1) → (0, 0, 2, 1)
  • (2, 3, 1) → (1, 2, 2)
  • (1, 2, 2) → (0, 1, 3)

So all the arrays you can possibly get are:

(2, 3, 1), (2, 2, 0, 1), (1, 1, 1, 1), (1, 1, 0, 0, 1), (0, 0, 1, 0, 1), (1, 0, 0, 2), (0, 0, 2, 1), (1, 2, 2), and (0, 1, 3)

Since there are 9 different arrays that you can reach, the answer is 9.

——————————————————————————————————

这道题明显每次只关系到相邻两位QAQ

所以我们可以从左到右dp

f【i】【j】【k】表示i-1位已经处理并且i值为i进位为k 所以i+1的值就是v【i+1】+k

然后我们就枚举操作次数x(x<=v【i+1】+k&&x<=j)推出i+1的情况就好辣

易得i个数比n打不了多少 我们求出最大的 i 答案就是f【i】【0】【0】辣

而j也不会超过一个值 这里我带了个200 至于k同理咯QAQ

时间: 2024-08-06 20:02:48

codechef AUG17 T5 Chef And Fibonacci Array的相关文章

codechef AUG17 T1 Chef and Rainbow Array

Chef and Rainbow Array Problem Code: RAINBOWA Chef likes all arrays equally. But he likes some arrays more equally than others. In particular, he loves Rainbow Arrays. An array is Rainbow if it has the following structure: First a1 elements equal 1.

codechef AUG17 T2 Chef and Mover

Chef and Mover Problem Code: CHEFMOVR Chef's dog Snuffles has so many things to play with! This time around, Snuffles has an array A containing N integers: A1, A2, ..., AN. Bad news: Snuffles only loves to play with an array in which all the elements

codechef AUG17 T3 Greedy Candidates

Greedy Candidates Problem Code: GCAC The placements/recruitment season is going on in various colleges. The interviews are over, and each company has selected some students. But since each student can end up finally in at most one company, a student

codechef AUG17 T4 Palindromic Game

Palindromic Game Problem Code: PALINGAM There are two players A, B playing a game. Player A has a string s with him, and player B has string t with him. Both s and t consist only of lower case English letters and are of equal length. A makes the firs

@codechef - [email&#160;protected] Chef and Same Old Recurrence 2

目录 @[email protected] @[email protected] @accepted [email protected] @[email protected] @[email protected] 定义 dp 序列: \[dp(1) = K\dp(n) = A\times dp(n-1) + B\times \sum_{i=1}^{n-1}dp(i)\times dp(n-i)\] Q 次询问,每次询问给出 L, R,求 \(\sum_{i=L}^{R}dp(i)^2\),对 1

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 th

CodeChef A String Game(SG)

A String Game Problem code: ASTRGAME Submit All Submissions All submissions for this problem are available. Teddy and Tracy like to play a game based on strings. The game is as follows. Initially, Tracy writes a long random string on a whiteboard. Th

9.27NOIP模拟题

NOIP 模拟测试 1 任务安排 manage.in/.out/.cpp1.1 问题描述你有 N 个工作,同一时刻只能做一个任务, 其中每个工作有其所需时间, 及完成的 Deadline(截止时间), 问要完成所有工作, 最迟要从什么时候开始.你最早可以从时间 0 开始工作.1.2 输入格式第一行一个整数 N,表示任务数量接下来 n 行,每行两个整数,T i ,S i ,分别表示该任务的持续时间和截止时间.1.3 输出格式输出一个整数,表示最晚的开始时间,如果不能完成,输出-1.1.4 样例输入

Dynamic Programming 动态规划

Dynamic Programming DP 的历史渊源: Richard E. Bellman (1920-1984) Richard Bellman received the IEEE Medal of Honor, 1979. "Bellman . . . explained that he invented the name 'dynamid programming' to hide the fact that he was doing mathe-matical research at