Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
USACO数据全过,交上去WA,求解释(附代码)#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #define rep(i,n) for (int i=1;i<=n;i++) #define fr(i,s,e) for (int i=s;i<=e;i++) #define INF 0x3f3f3f3f using namespace std; const int N=10005; int n,m,a,b,la,lb,p[N],f[2][N]; void init() { scanf("%d%d",&n,&m); rep(i,n) scanf("%d",&p[i-1]); } void dawn() { memset(f,0x3f,sizeof(f)); la=m/(n-1);lb=la+1; b=m%(n-1);a=n-1-b; f[0][0]=p[0]; fr(i,0,n-2) { int ii=i&1; fr(i,max(0,i+1-b),min(i+1,a)) f[1-ii][i]=INF; fr(j,max(0,i-b),min(i,a)) if (f[ii][j]!=INF) { int t=j*la+(i-j)*lb; f[1-ii][j]=min(f[1-ii][j],f[ii][j]+abs(p[i+1]-(t+lb))); f[1-ii][j+1]=min(f[1-ii][j+1],f[ii][j]+abs(p[i+1]-(t+la))); } } printf("%d\n",f[(n-1)&1][a]); } int main() { //freopen("1.txt","r",stdin); init(); dawn(); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator