- 过河
- 2015-10-26 12:23:13 @
手写快排+状压DP 按理说没问题啊,我都压的是极其**保守**的1260
可是
它就是过不了!!!!!!!
我知道是我**写丑了**,
但哪里丑啊啊啊啊啊啊啊啊啊。。。。
###Block Code
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
using namespace std;
int a[110],l,s,t,m,dp[1000000];
void quicksort(int left,int right) {
if (left >= right) return;
int t,i=left,j=right;
while (i<j) {
while (a[left]<=a[j] && i<j) j--;
while (a[i]<=a[left] && i<j) i++;
if (i!=j) {
t = a[i];
a[i] = a[j];
a[j] = t;
}
}
t = a[left];
a[left] = a[i];
a[i] = t;
quicksort(left,i-1);
quicksort(i+1,right);
return;
}
int main() {
//read
scanf("%d",&l);
scanf("%d%d%d",&s,&t,&m);
for (int i=1;i<=m;i++)
scanf("%d",&a[i]);
a[0]=0;
a[m+1]=l;
quicksort(1,m);
//compress
if (s==t) {
int total=0;
for (int i=1;i<=m;i++) {
if (a[i]%s==0)
total++;
}
printf("%d",total);
}
else {
for (int i=1;i<=m+1;i++) {
int lsg=a[i]-a[i-1];
lsg-=lsg%210;
for (int j=i;j<=m+1;j++)
a[j]=a[j]-lsg;
}
l=a[m+1];
dp[0]=0;
int now=1;
for (int i=1;i<=l;i++) {
int minx=99999999;
for (int j=s;j<=t;j++) {
if (i-j>=0)
if (dp[i-j]<minx)
minx=dp[i-j];
}
dp[i]=minx;
if (a[now]==i) {
now++;
dp[i]++;
}
}
int minx=999;
if (s>=l)
cout<<"0";
else {
for (int i=l-t;i<l;i++) {
if (i<0) continue;
if (dp[i]<minx) minx=dp[i];
}
printf("%d",minx);
}
}
return 0;
}
2 条评论
-
方晨羽 LV 9 @ 2016-08-13 14:33:24
开大了!!!
-
2016-07-01 09:11:47@
呵呵
- 1