1045. Favorite Color Stripe (3

原创 2016年08月29日 10:13:11

IDEA

1.本题是求最长连续子串,但是相同子串允许重复出现

2.采用动态规划方法,将动态表表示最大出现长度

    2 2 4 1 5 5 6 3 1 1 5 6
  0 0 0 0 0 0 0 0 0 0 0 0 0
2 0 1 2 2 2 2 2 2 2 2 2 2 2
3 0 1 2 2 2 2 2 2 3 3 3 3 3
1 0 1 2 2 3 3 3 3 3 4 4 4 4
5 0 1 2 2 3 4 5 5 5 5 5 6 6
6 0 1 2 2 3 4 5 6 6 6 6 6 7


CODE

#include<iostream>
#include<vector> 
#include<queue>
#include<algorithm>
#include<fstream>
using namespace std;
int fav[201]={0};
int given[10001]={0};
int dp_len[201][10001]={0};
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	#endif
	
	int n,m,l;
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>fav[i];
	}
	cin>>l;
	for(int i=1;i<=l;i++){
		cin>>given[i];
	}
	//动态规划算法 
	for(int i=1;i<=m;i++){
		for(int j=1;j<=l;j++){
			int mmax=max(dp_len[i][j-1],dp_len[i-1][j]);
			if(fav[i]==given[j]){
				dp_len[i][j]=mmax+1;
			}else{
				dp_len[i][j]=mmax;
			}
		}
	}
	cout<<dp_len[m][l];
	#ifndef ONLINE_JUDGE
	fclose(stdin);
	#endif
	return 0;
}


版权声明:

相关文章推荐

pat1045Favorite Color Stripe (30)

题意分析: (1)给出一个有若干个数的偏好序列,同时给出另一个任意的数组,并且参照前面序列中元素出现的相对顺序(某些元素可以丢弃)依次从前往后选择数组中的元素组成一个新的数组,求这个数组的最大长度。 ...

1045. Favorite Color Stripe (30)

1.这个和最长公共子序列问题相类似(LCS) 2.不同的地方是允许元素重复,如{a}和{aaa},匹配出来的是3,a可以重复3次 3.该问题一开始卡在了输入格式上 4.动态规划方程:dp[i][...

PAT 1045. Favorite Color Stripe (30)

1045. Favorite Color Stripe (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 ...

1045. Favorite Color Stripe (30)

题目: Eva is trying to make her own color stripe out of a given one. She would like to keep only her...

1045. Favorite Color Stripe (30)

#include#define MAX 205int like[MAX];int strip[10005];int lcs[MAX][10005];int main(){ int N,M,L; sca...

1045. Favorite Color Stripe (30)

Eva is trying to make her own color stripe out of a given one. She would like to keep only her favor...

1045. Favorite Color Stripe (30)

Eva is trying to make her own color stripe out of a given one. She would like to keep only her favor...

1045. Favorite Color Stripe (30)

Eva is trying to make her own color stripe out of a given one. She would like to keep only her favor...

PAT1045 Favorite Color Stripe

PATA1045

PAT--1045. Favorite Color Stripe(LIS)

Eva is trying to make her own color stripe out of a given one. She would like to keep only her favor...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)