zoukankan      html  css  js  c++  java
  • LuoguP1799 数列_NOI导刊2010提高 (动态规划)

    $ f[j]=max(f[i−1][j],f[i−1][j−1]+(x == j) $

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #define R(a,b,c) for(register int  a = (b); a <= (c); ++ a)
    #define nR(a,b,c) for(register int  a = (b); a >= (c); -- a)
    #define Max(a,b) ((a) > (b) ? (a) : (b))
    #define Min(a,b) ((a) < (b) ? (a) : (b))
    #define Fill(a,b) memset(a, b, sizeof(a))
    #define Swap(a,b) a^=b^=a^=b
    #define ll long long
    #define ON_DEBUG
    
    #ifdef ON_DEBUG
    
    #define D_e_Line printf("
    
    ----------
    
    ")
    #define D_e(x)  cout << #x << " = " << x << endl
    #define Pause() system("pause")
    
    #else
    
    #define D_e_Line ;
    
    #endif
    
    struct ios{
        template<typename ATP>ios& operator >> (ATP &x){
            x = 0; int f = 1; char c;
            for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-')  f = -1;
            while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
            x*= f;
            return *this;
        }
    }io;
    using namespace std;
    
    int f[1007];
    
    int main(){
    	int n;
    	io >> n;
    	R(i,1,n){
    		int x;
    		io >> x;
    		nR(j,i,1)
    			f[j] = Max(f[j], f[j-1] + (x == j));
    	}
    	int ans = 0;
    	R(i,1,n){
    		ans = Max(ans, f[i]);
    	}
    	printf("%d", ans);
    	return 0;
    }
    

  • 相关阅读:
    自定义Dialog
    AlertDialog
    Toast
    WebView
    《构建之法》阅读笔记3
    UI组件之GridView
    ScrollView&HorizontalScrollView
    UI组件之ImageView
    UI组件之ListView
    每周总结(1.24)
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11206111.html
Copyright © 2011-2022 走看看