占坑

J. Similar Subsequence
For given sequence A = (a1, a2, … , an), a sequence S = (s1, s2, … , sn) has shape A if and only if:
• si = min{si
, si+1, … , sn} for all ai = 0;
• si = max{si
, si+1, … , sn} for all ai = 1.
Given sequence B = (b1, b2, … , bm), Bobo would like to know the number of subsequences of length n which
have shape A modulo (109 + 7).
Input
The input contains zero or more test cases and is terminated by end-of-file. For each test case:
The first line contains two integers n and m.
The second line contains n integers a1, a2, … , an.
The thrid line contains m integers b1, b2, … , bm.
• The number of test cases does not exceed 10.
• 1 ≤ n ≤ 20
• 1 ≤ m ≤ 500
• 0 ≤ ai ≤ 1
• 1 ≤ bi ≤ m
• b1, b2, … , bm are distinct.
Output
For each case, output an integer which denotes the number of subsequences modulo (109 + 7).
Sample Input
2 3
0 0
1 2 3
3 5
1 0 1
4 1 3 2 5
Sample Output
3
2
Note
For the first sample, all three subsequences of length 2 are of shape A.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值