HDU 6078 dp
来源:互联网 发布:js 禁用input select 编辑:程序博客网 时间:2024/05/02 01:33
题目
Wavel Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 644 Accepted Submission(s): 335
Problem Description
Have you ever seen the wave? It's a wonderful view of nature. Little Q is attracted to such wonderful thing, he even likes everything that looks like wave. Formally, he defines a sequence a1,a2,...,an as ''wavel'' if and only if a1<a2>a3<a4>a5<a6...
Picture from Wikimedia Commons
Now given two sequencesa1,a2,...,an and b1,b2,...,bm , Little Q wants to find two sequences f1,f2,...,fk(1≤fi≤n,fi<fi+1) and g1,g2,...,gk(1≤gi≤m,gi<gi+1) , where afi=bgi always holds and sequence af1,af2,...,afk is ''wavel''.
Moreover, Little Q is wondering how many such two sequencesf and g he can find. Please write a program to help him figure out the answer.
Picture from Wikimedia Commons
Now given two sequences
Moreover, Little Q is wondering how many such two sequences
Input
The first line of the input contains an integer T(1≤T≤15) , denoting the number of test cases.
In each test case, there are2 integers n,m(1≤n,m≤2000) in the first line, denoting the length of a and b .
In the next line, there aren integers a1,a2,...,an(1≤ai≤2000) , denoting the sequence a .
Then in the next line, there arem integers b1,b2,...,bm(1≤bi≤2000) , denoting the sequence b .
In each test case, there are
In the next line, there are
Then in the next line, there are
Output
For each test case, print a single line containing an integer, denoting the answer. Since the answer may be very large, please print the answer modulo 998244353 .
Sample Input
13 51 5 34 1 1 5 3
Sample Output
10Hint(1)f=(1),g=(2).(2)f=(1),g=(3).(3)f=(2),g=(4).(4)f=(3),g=(5).(5)f=(1,2),g=(2,4).(6)f=(1,2),g=(3,4).(7)f=(1,3),g=(2,5).(8)f=(1,3),g=(3,5).(9)f=(1,2,3),g=(2,4,5).(10)f=(1,2,3),g=(3,4,5).
题目大意
看hint应该很好理解
解题思路
有点求最长公共子序列的意思,通过DP求解该点之前的波峰和波谷的数量。有机会再写一次吧
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;#define LL long long#define read(a) scanf("%d",&a)const int mod=998244353;int a[2000+10];int b[2000+10];LL dp[2000+10][2];LL sum[2000+10][2];void work(){ memset(dp,0,sizeof(dp)); memset(sum,0,sizeof(sum)); int n,m; read(n),read(m); LL ans=0; for(int i=1;i<=n;i++) read(a[i]); for(int i=1;i<=m;i++) read(b[i]); for(int i=1;i<=n;i++) { LL peak=1; LL val=0; for(int j=1;j<=m;j++) { if(a[i]==b[j]) { dp[j][0]=peak; dp[j][1]=val; ans=(ans+(peak+val)%mod)%mod; sum[j][0]=(sum[j][0]+dp[j][0])%mod; sum[j][1]=(sum[j][1]+dp[j][1])%mod; } else if(a[i]>b[j]) { val=(val+sum[j][0])%mod; } else { peak=(peak+sum[j][1])%mod; } } } printf("%lld\n",ans);}int main(){ int T; read(T); while(T--) { work(); } return 0;}
阅读全文
0 0
- HDU 6078 (计数DP)
- HDU 6078 dp
- hdu--6078--Wavel Sequence(dp)
- HDU DP
- DP? HDU
- DP? HDU
- DP? HDU
- 【dp】HDU
- 【dp】HDU
- 【dp】 HDU
- DP? HDU
- HDU 6078 Wavel Sequence【DP+优化】
- hdu 6078 Kanade's sum 计数dp
- HDU 6078 Wavel Sequence(dp)
- HDU 6078 Wavel Sequence (dp)
- HDU 1003 && HDU 1231 DP
- hdu 1058 DP
- HDU 1069 dp
- Gradle篇一——groovy基础
- html 表单
- Android系统从加电到Home桌面出现流程分析(基于Android-2.3)
- html 框架
- 【QT】Qt对大小端字节序的处理
- HDU 6078 dp
- css基础笔记总结
- 重构代码学习笔记一:重构的原则
- UVA 1331 【区间DP+三角剖分】
- 20170809 JAVA 方法的重写
- 汇编基础
- leetCode
- WEB-INF文件下建了目录无法跳转的原因
- 【QT】Qt QFlags源码分析