问:dp完了求出长度后怎么办?
  • 板块AT_dp_f LCS
  • 楼主Dcchen
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/7/21 21:22
  • 上次更新2024/7/21 23:40:34
查看原帖
问:dp完了求出长度后怎么办?
1012241
Dcchen楼主2024/7/21 21:22

dp完了求出长度后怎么办?需要一个适用 string的写法, 因为用题解区的char数组套进string输不出来。

我的代码:

#include<iostream>
#include<string.h>
using namespace std;
string s,t,sans;
int dp[3005][3005];
int main(){
    cin>>s>>t;
    s=" "+s;
    t=" "+t;
	int lena=s.size();
	int lenb=t.size();
	for(int i=1;i<=lena;i++){
		for(int j=1;j<=lenb;j++){
			dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
			if(s[i]==t[i]) dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
		}
	}
  怎么写???
  cout<<ans;
  return 0;
}
2024/7/21 21:22
加载中...