http://acm.hdu.edu.cn/showproblem.php?pid=5791

HDU5791 Two

题意 :两个数组,多少个不连续子串相等

思路:

dp[i][j] :a串i结尾,b串j结尾的不连续子串数目个数

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn=1e3+;
const int mod=1e9+;
const int inf=0x3f3f3f3f;
ll dp[maxn][maxn],a[maxn],b[maxn];
int n,m;
int main(){
while(~scanf("%d%d",&n,&m)){
for(int i=;i<=n;i++)scanf("%lld",&a[i]);
for(int i=;i<=m;i++)scanf("%lld",&b[i]);
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
dp[i][j]=(dp[i-][j]+dp[i][j-]-dp[i-][j-]+(a[i]==b[j]?dp[i-][j-]+:)+mod)%mod;
}
}
printf("%lld\n",dp[n][m]);
}
return ;
}

2016 Multi-University Training Contest 5 1011 Two DP的更多相关文章

  1. 2016 Al-Baath University Training Camp Contest-1

    2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...

  2. 2016 Multi-University Training Contest 3 1011【鸽巢原理】

    题解: 坐标(0,m)的话,闭区间,可能一共有多少曼哈顿距离? 2m 但是给一个n,可能存在n(n+1)/2个曼哈顿距离 所以可以用抽屉原理了 当n比抽屉的数量大,直接输出yes 不用计算 那...N ...

  3. 2016 Al-Baath University Training Camp Contest-1 E

    Description ACM-SCPC-2017 is approaching every university is trying to do its best in order to be th ...

  4. 2016 Al-Baath University Training Camp Contest-1 C

    Description Rami went back from school and he had an easy homework about bitwise operations (and,or, ...

  5. 2016 Al-Baath University Training Camp Contest-1 A

    Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...

  6. 2016 Al-Baath University Training Camp Contest-1 J

    Description X is fighting beasts in the forest, in order to have a better chance to survive he's gon ...

  7. 2016 Al-Baath University Training Camp Contest-1 I

    Description It is raining again! Youssef really forgot that there is a chance of rain in March, so h ...

  8. 2016 Al-Baath University Training Camp Contest-1 H

     Description You've possibly heard about 'The Endless River'. However, if not, we are introducing it ...

  9. 2016 Al-Baath University Training Camp Contest-1 G

    Description The forces of evil are about to disappear since our hero is now on top on the tower of e ...

随机推荐

  1. Ado.Net小练习03(省市联动)

    前台界面:          后台代码: namespace _04省市联动 {     public partial class Form1 : Form     {         public ...

  2. NSMutableArray 初始化与添加删除程序

           Person *person1=[[Person alloc]initWithName:@"Kenshin"];        Person *person2=[[P ...

  3. python 有关矩阵行列的存取 np.array

    初始化 a = range() a = np.array(a) a = a.reshape(,) a [[ 0  1  2  3]  [ 4  5  6  7]  [ 8  9 10 11]  [12 ...

  4. .net通过获取客户端IP地址反查出用户的计算机名

    这个功能看似很少用到,但又非常实用,看似简单,但又在其中存在很多未知因素造成让人悲痛莫名的负能量... 这是公司内部最近在使用的功能,因为是DHCP,所以有时会根据计算机名做一些统计和权限的设置. 也 ...

  5. 【转】深入解析cookie

    来源:http://www.freebuf.com/articles/web/42802.html 写的超级详细,mark下,刚好学习爬虫的时候,有用到cookie模仿登录的,就顺便了解下. 0×00 ...

  6. 字符设备 register_chrdev_region()、alloc_chrdev_region() 和 register_chrdev()

    1. 字符设备结构体 内核中所有已分配的字符设备编号都记录在一个名为 chrdevs 散列表里.该散列表中的每一个元素是一个 char_device_struct 结构,它的定义如下: static ...

  7. HDU 4565 So Easy!(矩阵)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4565 题意: 题意: #include <iostream>#include <cs ...

  8. [HDOJ4027]Can you answer these queries?(线段树,特殊成段更新,成段查询)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4027 RT,该题要求每次更新是更新所有节点,分别求平方根,查询是求和.昨晚思前想后找有没有一个数学上的 ...

  9. 注意:C++中double的表示是有误差的

    注意:C++中double的表示是有误差的,直接通过下面的例子看一下 #include<iostream> using namespace std; int main() { double ...

  10. poj 1185 炮兵阵地(三维状态压缩dP)

    题目:http://poj.org/problem?id=1185 思路: d[i][j][k]表示第i行的状态为第k个状态,第i-1行的状态为第j个状态的时候 的炮的数量. 1表示放大炮, 地形状态 ...