Hdu6078Wavel Sequence
来源:互联网 发布:淘宝手机排名突然没了 编辑:程序博客网 时间:2024/04/28 12:21
Wavel Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 582 Accepted Submission(s): 301
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).
Source
2017 Multi-University Training Contest - Team 4
——————————————————————————————————
题意:规定a1< a2 > a3 < a4 > a5 < a6……的数组为波浪数组,且第一个数必须为波谷,给定数组a,b,找出a中的波浪数组在b中有几组存在
解题思路:dp[i][0]存放b[i]作为波谷时的情况,dp[i][1]存放b[i]作为波峰时的情况。然后枚举a数组,在b数组中去找和a[i]一样的位置,找到后更新答案
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <string>#include <math.h>#include <time.h>#include <algorithm>#include <complex>#include <vector>#include <stack>#include <queue>#include <map>#include <set>using namespace std;#define LL long long#define mem(a,b) memset(a,b,sizeof a);const int inf=0x3f3f3f3f;const LL llinf=0x3f3f3f3f3f3f3f3f;const double pi=acos(-1.0);const double eps=1e-8;const LL mod=998244353;const int maxn=2010;LL dp[maxn][2];int a[maxn],b[maxn];int main(){ int T; int n,m; for(scanf("%d",&T); T--;) { mem(dp,0); scanf("%d%d",&n,&m); for(int i=1; i<=n; i++) scanf("%d",&a[i]); for(int i=1; i<=m; i++) scanf("%d",&b[i]); LL ans=0; mem(dp,0); for(int i=1; i<=n; i++) { LL l=1,h=0; for(int j=1; j<=m; j++) { if(a[i]==b[j]) { dp[j][0]+=l,dp[j][1]+=h; ans=(ans+(l+h)%mod)%mod; } else if(b[j]<a[i]) h=(h+dp[j][0])%mod; else l=(l+dp[j][1])%mod; } } printf("%lld\n",ans); } return 0;}
Wavel Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 582 Accepted Submission(s): 301
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).
Source
2017 Multi-University Training Contest - Team 4
阅读全文
0 0
- HDU6078Wavel Sequence
- Hdu6078Wavel Sequence
- HDU6078Wavel Sequence(计数dp)
- sequence
- SEQUENCE
- Sequence
- sequence
- sequence
- Sequence
- sequence
- sequence
- sequence
- Sequence
- Sequence
- Sequence
- Sequence
- sequence
- sequence
- HDU 1072 Nightmare BFS
- 华为软件开发云CloudIDE功能简测
- python pandas.errors Buffer overflow caught
- 使用 NTP 解决 Ceph 集群的时钟偏移
- 动态规划
- Hdu6078Wavel Sequence
- 双目匹配过程记录
- SSL协议握手过程
- 设计模式初探-桥接模式
- 集合
- Hibernate中使用@Temporal修饰日期类型的属性
- SEO(搜索引擎优化)百度鼓励原创,那么如何判断呢,百度原创识别“起源”算法与星火计划
- Python3+OpenCV人脸识别
- 域名解析到本地主机