zoukankan      html  css  js  c++  java
  • DP(第三版(较简单))

    突然很想找点DP题(被虐虐)

    前言

      我竟然还能想起来当时是怎么做的233,题都是随便找的,跟以前的代码重了就重了吧,反正风格变了qaq

      【2017-11-18】其实本来打算写好多好多的水题来着,不过要AFO啦,就不弄啦!

    1.codevs 1576 最长严格上升子序列

    直通

    代码酱(:3▓▒

    #include <iostream>
    #include <cstdio>
    using namespace std;
    
    const int N = 5005;
    int n,ans;
    int a[N],f[N];
    
    int main() {
        scanf("%d",&n);
        for(int i=1; i<=n; i++) {
            scanf("%d",&a[i]);
            f[i]=1;
            for(int j=i-1; j>=1; j--)
                if(a[i]>a[j])
                    f[i]=max(f[i],f[j]+1);
        }
        for(int i=1; i<=n; i++) ans=max(ans,f[i]);
        printf("%d",ans);
        return 0;
    }
    View Code

    2.luogu P1679 神奇的四次方数

    直通

    令人窒息的打表操作+背包DP

    代码酱_(:з」∠)_

    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    using namespace std;
    
    const int po[18] = {
        0,1,16,81,256,625,1296,2401,
        4096,6561,10000,14641,20736,
        28561,38416,50625,65536,83521
    };
    int m,dp[100010];
    
    int main() {
        scanf("%d",&m);
        memset(dp,0x7f,sizeof(dp));
        dp[0]=0;
        for(int i=1; i<=17; i++) 
            for(int j=po[i]; j<=m; j++)
                dp[j]=min(dp[j],dp[j-po[i]]+1);
        printf("%d",dp[m]);
        return 0;
    }
    View Code
  • 相关阅读:
    android-layout-finder 在线生成findViewById
    Android 广播机制
    Android Service随笔
    新博客地址(https://minxin.github.io)
    angr学习(四)
    angr学习(三)
    angr学习(二)
    angr学习(一)
    android studio NDK开发方案
    python虚拟机
  • 原文地址:https://www.cnblogs.com/zxqxwnngztxx/p/7806487.html
Copyright © 2011-2022 走看看