标签:out return div queue vector algorithm main its ext
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; }
标签:out return div queue vector algorithm main its ext
原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/10854010.html