P1052 [NOIP2005 提高组] 过河
关键在于压缩长度
不会证明怎么办
感性理解开个大数\(s*t*10\)
#include<cstdio>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<cmath>
#include<algorithm>
using namespace std;
template<class T>inline void read(T &x)
{
x=0;register char c=getchar();register bool f=0;
while(!isdigit(c))f^=c=='-',c=getchar();
while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
if(f)x=-x;
}
template<class T>inline void print(T x)
{
if(x<0)putchar('-'),x=-x;
if(x>9)print(x/10);
putchar('0'+x%10);
}
int l;
int s,t,m;
int f[3000000];
int dis;
int ans;
int nd[3000000];
int a[3000000];
int main(){
read(l);
read(s);read(t);read(m);
for(int i=1;i<=m;++i){
read(a[i]);
}
sort(a+1,a+m+1);
a[m+1]=l;
m++;
if(s==t){
int cnt=0;
for(int i=1;i<=m;++i){
if(a[i]%s==0){
cnt++;
}
}
cout<<cnt;
return 0;
}else{
for(int i=1;i<=m;++i){
dis+=min(a[i]-a[i-1],s*t*10);
nd[dis]=1;
}
nd[dis]=0;
memset(f,0x3f,sizeof(f));
f[0]=0;
for(int i=1;i<=dis+9;++i){
for(int j=s;j<=t;++j){
if(i-j<0) continue;
f[i]=min(f[i],f[i-j]);
}
f[i]+=nd[i];
}
int cnt=99999999999;
for(int i=0;i<=9;++i){
cnt=min(cnt,f[i+dis]);
}
cout<<cnt;
}
return 0;
}