LOJ2500 NOIP2014 flying birds [backpack DP]*

Posted by Frank H. Shaw on Tue, 31 Dec 2019 10:18:34 +0100

LOJ2500 NOIP2014 flying birds


The main idea of the topic is that there are n columns. You can choose not to lower the height y and increase x * px * p every second. If the current position plus x * px * P is greater than the upper bound m, it will stop at M.
If you can successfully cross all columns, output the minimum number of clicks, otherwise output the maximum number of columns you can cross

The feeling is very obvious DP. If you don't click, it's a 01 knapsack. When you click, it's a complete knapsack
Therefore, it can be set that dp[i][j]dp[i][j] is the minimum number of steps to reach the height of column I of j

And then you can find the transfer
It's like this when it's falling down
And then when it comes to complete backpacking, it can become a contribution that only considers one click at a time and then adds all the contributions

Then, it should be noted that the influence factors of the lower bound cannot be considered when the backpack is completely transferred, because the next pillar is not reached by default when the backpack is transferred
Finally, after the transfer, add the influence of the lower bound

And then it's down. It's up. It's up

using namespace std;
#define M 1010
#define N 10010
#define INF 0x3f3f3f3f
int dp[2][N],ind=0;
int n,m;
int k,p[N],l[N],r[N];
int x[N],y[N];
int main(){
    for(int i=1;i<=n;i++)scanf("%d%d",&x[i],&y[i]);
    for(int i=1;i<=k;i++){
        int p,ll,rr;
    for(int i=1;i<=n;i++)if(l[i]==0&&r[i]==0)l[i]=1,r[i]=m;
    for(int i=1;i<=m;i++)dp[ind][i]=0;
    int tot=0;
    for(int i=1;i<=n;i++){
        int dw=l[i],up=r[i];
        for(int j=x[i];j<=up;j++)
        if(up==m)for(int j=m-x[i];j<=m;j++)
        for(int j=dw;j<=min(up,m-y[i]);j++)
        for(int j=1;j<dw;j++)dp[ind][j]=INF;
        bool check=0;
        for(int j=1;j<=m;j++)
        if(!check){printf("0\n%d",tot);return 0;}
    int ans=INF;
    for(int i=1;i<=m;i++)ans=min(ans,dp[ind][i]);
    return 0;