DP一直是自己的弱势 开始练滚动数组——HDOJ4502

http://acm.hdu.edu.cn/showproblem.php?pid=4502//题目链接

思路 : dp[i]表示 到第i天能获得的最大工资  依次更新

#include<cstdio>
#include<map>
//#include<bits/stdc++.h>
#include<vector>
#include<stack>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<cstdlib> 
#include<climits>
#define PI acos(-1.0)
#define INF 0x3fffffff
using namespace std;
typedef long long ll;
typedef __int64 int64;
const ll mood=1e9+7;
const int64 Mod=998244353;
const double eps=1e-9;
const int N=1e3+10;
const int MAXN=200000;
typedef int rl; 
inline void r(rl&num){
    num=0;rl f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
    num*=f;
}
int dp[N];//dp[i] 滚动数组 
struct xxxx{
    int st,en,val;
}data[N];
bool cmp(struct xxxx a,struct xxxx b)
{
    return a.st<b.st;
}
int main()
{
    int ci;
    r(ci);
    int n,m;
    while(ci--)
    {
        r(m);r(n); //m假期时间 n工作数目 
        memset(dp,0,sizeof(dp));
        for(int i=0;i<n;i++)
        {
            r(data[i].st);r(data[i].en);r(data[i].val);
        }
        for(int i=1;i<=m;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(data[j].en<=i)dp[i]=max(dp[i],dp[data[j].st-1]+data[j].val);
            }
        }
        printf("%d
",dp[m]);
    }
    return 0;
} 
滚动数组
原文地址:https://www.cnblogs.com/Geek-xiyang/p/5309100.html