P1052 solution to a problem across the river

Review dp ( dupuy ) when the brush to a simple path compression subject (it will not qwq)

Title Description link .

Correct answer:

First, let's see the topic, naturally think of this idea:

DP setting state variable [i] represents a lattice has elapsed from the first hop skip some of the most number of pebbles on the i-th grid is stepped on.

Well, according to every hop s ~ t grid, we can draw dp [i] can go to dp [is] transferred from dp [it] up, to consider the words of it, it should take in a situation before in all plus the minimum number of stones in the stone whether the the current position, is dp [i] value.

So then, with the whole idea, we began to beat the code.

I found such a thing while browsing the range of the array:

 

awsl

 

 

This space of time it will explode. . .

Ever since, we have the above routine was simple ban out.

I began to think:

 

 

We found this data, the interval between the stones become very large.

You can compress those extra path, but did not affect it but then the answer?

 First of all, the removal of problem solution in a valley of Los dalao approach:

 

 

 I did not see directly, to be ex.

To think for themselves:

I looked at the data range:

 Observation equation dp dp [i] = max (dp [it] ~ dp [is]) + flag [i]; flag [i] denotes the i-th position has no stones.

When a piece of gravel section does not exist, flag it useless.

Thus it plainly, statistical process is statistical maximum once finished dp [i] to a maximum dp [it], which is equal to zero behind the flag can be directly skipped.

It is not difficult to come up, statistics dp [i] to dp [it] This section needs a total maximum lcm (s, t) times.

Emotional understanding. . .

Then we derive the minimum compressed length of 90 .. ? (90 = 9 * 10,10,10 case of direct special sentence on the line)

So, the extra distance 90 are compressed into 90 must be able to guarantee the same results.

On the code:

#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 214748364 
using namespace std;
int read()
{
    int ans=0;
    char ch=getchar(),last=' ';
    while(ch>'9'||ch<'0')last=ch,ch=getchar();
    while(ch>='0'&&ch<='9')ans=(ans<<3)+(ans<< 1)+ch-'0',ch=getchar();
    return last=='-'?-ans:ans;
}
int min(int a,int b){return a<b?a:b;}

inline bool cmp(int a,int b)
{return a<b;}

int l,s,t,m,sz[20003],ans,dis[20003],sum,flag[20001],dp[20001];

int main(){
    l=read();
    s=read(),t=read(),m=read();
    if(s==t)
    {
        int bol;
        for(int i=1;i<=m;i++)
        {
            bol=read();ans+=((bol%s)==0);
        }
        printf("%d\n",ans);return 0;
    }
    for(int i=1;i<=m;i++)
        sz[i]=read();
    sort(sz+1,sz+1+ M, CMP);
     for ( int I = . 1 ; I <= m; I ++ ) 
        DIS [I] = min (SZ [I] -SZ [I- . 1 ], 90 ); // DIS [I] denotes i-stone to the distance between the first i-1 a stone difference 
    DIS [m + . 1 ] = min (L-SZ [m], 100 );
     for ( int i = . 1 ; i <= m; i ++ ) 
        SUM + = DIS [ I], In Flag [SUM] = . 1 ; 
    SUM + DIS = [m + . 1 ];
     for ( int I = . 1 ; I <= SUM + . 9 ; I ++ ) 
    { 
        DP [I]=maxn;
        for(int j=s;j<=t;j++)
        {
            if(i>=j)dp[i]=min(dp[i],dp[i-j]+flag[i]);
        }
    }
    int minn=maxn;
    for(int i=sum;i<=sum+9;i++)
    {
        minn=min(minn,dp[i]);
    }
    printf("%d",minn);
    return 0;
}

end/

 

 That is, for the extreme case s = t = 10, as long as there are no stones to see statistics on the line on a multiple of 100.

For the case where the second largest s = 9, t = 10, when, as long as the s

Guess you like

Origin www.cnblogs.com/lbssxz/p/11512697.html