uva-111-dp
Posted shuiyonglewodezzzzz
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了uva-111-dp相关的知识,希望对你有一定的参考价值。
DAG图上的DP
#include <string> #include<iostream> #include<map> #include<memory.h> #include<vector> #include<algorithm> #include<queue> #include<vector> #include<stack> #include<math.h> #include<iomanip> #include<bitset> #include"math.h" namespace cc { using std::cout; using std::endl; using std::cin; using std::map; using std::vector; using std::string; using std::sort; using std::priority_queue; using std::greater; using std::vector; using std::swap; using std::stack; using std::queue; using std::bitset; constexpr int N = 25; int a[N]; int c[N]; int b[N][N]; void solve() { int n; cin >> n; int k; for (int i = 1;i <= n;i++) { cin >> k; a[k] = i; } while (cin >> k) { c[k] = 1; for (int i = 2;i <= n;i++) { cin >> k; c[k] = i; } for (int i=1;i<=n;i++) { for (int j=1;j<=n;j++) { if (a[i] == c[j]) b[i][j] = b[i - 1][j - 1] + 1; else if (b[i - 1][j] > b[i][j - 1]) b[i][j] = b[i-1][j]; else b[i][j] = b[i][j-1]; } } cout << b[n][n] << endl; } } }; int main() { #ifndef ONLINE_JUDGE freopen("d://1.text", "r", stdin); #endif // !ONLINE_JUDGE cc::solve(); return 0; }
以上是关于uva-111-dp的主要内容,如果未能解决你的问题,请参考以下文章