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值为j进位为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

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

  1. codechef AUG17 T1 Chef and Rainbow Array

    Chef and Rainbow Array Problem Code: RAINBOWA Chef likes all arrays equally. But he likes some array ...

  2. 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 ...

  3. codechef AUG17 T3 Greedy Candidates

    Greedy Candidates Problem Code: GCAC The placements/recruitment season is going on in various colleg ...

  4. CodeChef SADPAIRS:Chef and Sad Pairs

    vjudge 首先显然要建立圆方树 对于每一种点建立虚树,考虑这一种点贡献,对于虚树上已经有的点就直接算 否则对虚树上的一条边 \((u, v)\),\(u\) 为父亲,假设上面连通块大小为 \(x\ ...

  5. codechef AUG17 T4 Palindromic Game

    Palindromic Game Problem Code: PALINGAM There are two players A, B playing a game. Player A has a st ...

  6. CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And Easy Xor Queries

    https://www.codechef.com/DEC17/problems/CHEFEXQ 题意: 位置i的数改为k 询问区间[1,i]内有多少个前缀的异或和为k 分块 sum[i][j] 表示第 ...

  7. CodeChef CHEFSOC2 Chef and Big Soccer 水dp

    Chef and Big Soccer   Problem code: CHEFSOC2 Tweet     ALL SUBMISSIONS All submissions for this prob ...

  8. Codechef FNCS Chef and Churu

    Disciption Chef has recently learnt Function and Addition. He is too exited to teach this to his fri ...

  9. codechef May Challenge 2016 CHSC: Che and ig Soccer dfs处理

    Description All submissions for this problem are available. Read problems statements in Mandarin Chi ...

随机推荐

  1. swiper动画效果

    参考swiper官方网站:http://www.swiper.com.cn/ Swiper常用于移动端网站的内容触摸滑动: 结构展示:   纯javascript打造的滑动特效插件,面向手机.平板电脑 ...

  2. 洛谷P2908 [USACO08OPEN]文字的力量Word Power

    题目描述 Farmer John wants to evaluate the quality of the names of his N (1 <= N <= 1000) cows. Ea ...

  3. org.hibernate.hql.internal.ast.QuerysyntaxException:user is not mapped [from User where user_code=? and user_password=?]

    初学者,一个很低级的错误吧! 找不到映射,最后发现没把类的Hibernate映射文件 添加到Hibernate核心配置文件中去,所以报了这个异常! 在核心文件中添加映射   <mapping r ...

  4. 16.2--Jenkins+Maven+Gitlab+Tomcat 自动化构建打包、部署

    分类: Linux服务篇,Linux架构篇   一.环境需求 本帖针对的是Linux环境,Windows或其他系统也可借鉴.具体只讲述Jenkins配置以及整个流程的实现. 1.JDK(或JRE)及J ...

  5. GNU汇编逻辑或算数左移右移

    lsl 左移 .text .global  _start _start: mov r1,#0b1 mov r1,r1,lsl#2 ROR循环右移 .text .global  _start _star ...

  6. 16.VUE学习之-v-show的使用与v-if的差异对比

    v-show的使用与v-if的差异对比 相同点: 都可以达到隐藏和显示的效果. 不同点: v-show 会用display:none 来隐藏元素节点,推荐使用这种方式 v-if 会移除节点,可以配合v ...

  7. Admin站点

    使用admin站点 a.在settings.py中设置语言和时区 LANGUAGE_CODE = 'zh-hans' # 使用中国语言 TIME_ZONE = 'Asia/Shanghai' # 使用 ...

  8. Redis实现之字符串

    简单动态字符串 Redis中的字符串并不是传统的C语言字符串(即字符数组,以下简称C字符串),而是自己构建了一种简单动态字符串(simple dynamic string,SDS),并将SDS作为Re ...

  9. TCP/IP网络编程之地址族与数据序列

    分配IP地址和端口号 IP是Internet Protocol(网络协议)的简写,是为收发网络数据而分配给计算机的值.端口号并非赋予计算机的值,而是为区分程序中创建的套接字而分配给套接字的序号 网络地 ...

  10. loj2537 「PKUWC 2018」Minimax

    pkusc 快到了--做点题涨涨 rp. 初见时 yy 了一个类似于归并的东西,\(O(n^2)\),50 分. 50 分 yy 做法 对于一个点,枚举他能到达的权值(假设这个权值在左子树,在右子树是 ...