POJ 1458 Common Subsequence
来源:互联网 发布:js 对象排序 sort 编辑:程序博客网 时间:2024/05/16 18:58
题意:求最长公共子序列
链接:http://poj.org/problem?id=1458
思路:LCS模板题,状态转移方程dp[n][j] = max ( dp[n][j-1], dp[n^1][j-1] ) + ( a[i] == b[j] ) ? 1:0
注意点:无
以下为AC代码:
Run IDUserProblemResultMemoryTimeLanguageCode LengthSubmit Time14185907luminous111458Accepted8532K63MSG++3049B2015-05-12 09:50:15#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <iostream>#include <cstring>#include <cstdio>#include <string>#include <vector>#include <deque>#include <list>#include <map>#include <set>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <cctype>#include <climits>#include <iomanip>#include <cstdlib>#include <algorithm>//#include <unordered_map>//#include <unordered_set>#define ll long long#define ull unsigned long long#define all(x) (x).begin(), (x).end()#define clr(a, v) memset( a , v , sizeof(a) )#define pb push_back#define RDI(a) scanf ( "%d", &a )#define RDII(a, b) scanf ( "%d%d", &a, &b )#define RDIII(a, b, c) scanf ( "%d%d%d", &a, &b, &c )#define RS(s) scanf ( "%s", s )#define PI(a) printf ( "%d", a )#define PIL(a) printf ( "%d\n", a )#define PII(a,b) printf ( "%d %d", a, b )#define PIIL(a,b) printf ( "%d %d\n", a, b )#define PIII(a,b,c) printf ( "%d %d %d", a, b, c )#define PIIIL(a,b,c) printf ( "%d %d %d\n", a, b, c )#define PL() printf ( "\n" )#define PSL(s) printf ( "%s\n", s )#define rep(i,m,n) for ( int i = m; i < n; i ++ )#define REP(i,m,n) for ( int i = m; i <= n; i ++ )#define dep(i,m,n) for ( int i = m; i > n; i -- )#define DEP(i,m,n) for ( int i = m; i >= n; i -- )#define repi(i,m,n,k) for ( int i = m; i < n; i += k )#define REPI(i,m,n,k) for ( int i = m; i <= n; i += k )#define depi(i,m,n,k) for ( int i = m; i > n; i += k )#define DEPI(i,m,n,k) for ( int i = m; i >= n; i -= k )#define READ(f) freopen(f, "r", stdin)#define WRITE(f) freopen(f, "w", stdout)using namespace std;const double pi = acos(-1);template <class T>inline bool RD ( T &ret ){ char c; int sgn; if ( c = getchar(), c ==EOF )return 0; //EOF while ( c != '-' && ( c < '0' || c > '9' ) ) c = getchar(); sgn = ( c == '-' ) ? -1 : 1; ret = ( c == '-' ) ? 0 : ( c - '0' ); while ( c = getchar() , c >= '0' && c <= '9' ) ret = ret * 10 + ( c - '0' ); ret *= sgn; return 1;}inline void PD ( int x ){ if ( x > 9 ) PD ( x / 10 ); putchar ( x % 10 + '0' );}const double eps = 1e-10;const int dir[4][2] = { 1,0, -1,0, 0,1, 0,-1 };struct node{ int x, y, cnt; node(){} node( int _x, int _y ) : x(_x), y(_y) {} node( int _x, int _y, int _cnt ) : x(_x), y(_y), cnt(_cnt) {}};string a, b;int dp[2][1000005];int main(){ ios::sync_with_stdio( false ); while ( cin >> a >> b ){ clr ( dp, 0 ); int ans = 0; rep ( i, 0, a.size() ){ int n = i & 1; rep ( j, 0, b.size() ){ if ( a[i] == b[j] ){ dp[n][j] = max ( dp[n][j-1], dp[n^1][j-1] + 1 ); } else{ dp[n][j] = max ( dp[n][j-1], dp[n^1][j] ); } ans = max ( dp[n][j], ans ); } } cout << ans << endl; } return 0;}
0 0
- Common Subsequence--poj--1458
- poj 1458 Common Subsequence
- poj 1458 Common Subsequence
- Poj 1458 Common Subsequence
- POJ 1458 Common Subsequence
- poj 1458 Common Subsequence
- poj 1458 Common Subsequence
- POJ 1458 Common Subsequence
- poj 1458 Common Subsequence
- POJ-1458-Common Subsequence
- POJ 1458 Common Subsequence
- poj 1458 Common Subsequence
- POJ 1458 Common Subsequence
- poj 1458 Common Subsequence
- POJ 1458 Common Subsequence
- POJ 1458 Common Subsequence
- POJ 1458 Common Subsequence
- poj 1458 Common Subsequence
- TCP和UDP区别
- 安装Rust
- js正则表达式语法
- Solr索引Oracle数据库的基本配置
- redhat下mongodb的安装
- POJ 1458 Common Subsequence
- [BUG修复]swith 引起的: expected expression的 error-
- dbca后报错libclntsh.so.11.1
- 谁在扼杀中国互联网的创新能力?
- "通常每个套接字地址(协议/网络地址/端口)只允许使用一次"
- 返回数据处理
- OC 语法总结
- java观察者模式
- Inkpad应用项目源码完整版