标签:== cstring memset names while element put 注意 ace
Input
Output
对于每组数据,输出真实事件序列的最长可能长度。
Sample Input
1 9 1 4 2 6 3 8 5 9 1 6 2 7 6 3 5 1
Sample Output
3
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> using namespace std; const int N = 1000 + 5; int dp[N], a[N], b[N]; void Work(int n, int m){ int M; memset(dp, 0, sizeof(dp)); for(int i = 1; i <= n; i++){ M = 0; for(int j = 1; j <= m; j++){ if(a[i] > b[j] && M < dp[j]) M = dp[j]; if(a[i] == b[j]) dp[j] = M + 1; } } printf("%d\n", *max_element(dp + 1, dp + m + 1)); } int main(){ int T, n, m; scanf("%d", &T); while(T --){ scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%d", &a[i]); scanf("%d", &m); for(int i = 1; i <= m; i++) scanf("%d", &b[i]); Work(n, m); } }
标签:== cstring memset names while element put 注意 ace
原文地址:http://www.cnblogs.com/Pretty9/p/7406937.html