• poj 3666 Making the Grade


    题意:给你一个序列,让你变成一个不递增或者一个不递减序列(ps:不递增就是可以不严格,这样说还真是绕口QAQ)

    思路:之前没想到状态是怎么定义的,看了几篇题解,发现大家定义的都是长度和变化的值,我最开始一直以为是dp【n】【3】(但我好像懂了,因为【3】只能代表加减和不变,并不知道你变了多少,所以取全部),但是1e9肯定开不下,所以进行离散化处理,这个题还有一点不懂就是不知道为什最优解一定是出现在原来的序列中,如果有大佬知道为什么的话欢迎留言,教教鶸。

    代码:

    #include <set>
    #include <map>
    #include <queue>
    #include <stack>
    #include <math.h>
    #include <vector>
    #include <string>
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <iostream>
    #include <algorithm>
    #define zero(a) fabs(a)<eps
    #define max( x, y )  ( ((x) > (y)) ? (x) : (y) )
    #define min( x, y )  ( ((x) < (y)) ? (x) : (y) )
    #define lowbit(x) (x&(-x))
    #define debug(a) cerr<<#a<<"=="<<a<<endl
    typedef long long ll;
    const double pi=acos(-1.0);
    const double eps=1e-8;
    const int inf=0x3f3f3f3f;
    const ll linf=0x3f3f3f3f3f3f3f3f;
    using namespace std;
    
    const int maxn=2007;
    int a[maxn],b[maxn],n,dp[maxn][maxn];
    
    int main()
    {
        while(~scanf("%d",&n)){
            for(int i=1;i<=n;i++){
                scanf("%d",&a[i]);
                b[i]=a[i];
            }
            sort(b+1,b+n+1);
            int last;
            for(int i=1;i<=n;i++){
                last=inf;
                for(int j=1;j<=n;j++){
                    last=min(last,dp[i-1][j]);
                    dp[i][j]=last+fabs(b[j]-a[i]);
                }
            }
            int ans=inf;
            for(int i=1;i<=n;i++){
                ans=min(ans,dp[n][i]);
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    cmake的安装
    安装cmake过程g++: 错误:unrecognized command line option ‘-std=gnu++14’
    进程空间分配
    git 基本操作
    nm命令
    container_of 宏
    cmake
    fiddler修改Requests之前的数据和response 之后的数据
    Fiddler抓包请求前设置断点
    jmeter连接mysql数据库
  • 原文地址:https://www.cnblogs.com/lalalatianlalu/p/8452807.html
Copyright © 2020-2023  润新知