zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    SpringBoot整合Redis缓存
    手写一个json格式化 api
    MYSQL 5.7 无法启动(Could not open error log file errno 2)
    如何获取算法运行状态
    Spring MVC
    Java设计模式
    Java设计模式
    Java设计模式
    Java设计模式
    学习myBatis
  • 原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/10854010.html
Copyright © 2011-2022 走看看