| ||||||||||
| 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 | |||||||||
Re:Runtime Error 是什么错误啊,我用的是动态规划,开了两个数组,f[100001][100001]和w[100001]In Reply To:Re:Runtime Error 是什么错误啊,我用的是动态规划,开了两个数组,f[100001][100001]和w[100001] Posted by:IronStill at 2007-07-22 08:55:51 我用的是f[2][100001]结果也是runtime error!
我用的是循环+动态规划,代码如下:
#include <iostream.h>
int n,m;
long a[100001];
long f[2][100001];
long min(const long &p,const long &q);
long max(const long &p,const long &q);
void main()
{
int i,p,q,cha = 0;
long sum,temp1,temp2;
cin>>n>>m;
cha = n-m;
for(i=1;i<=n;i++)
{cin>>a[i];}
//cout<<"input over!!"<<endl;
f[0][1] = 0;
for(i=1;i<=(n-m+1);i++)
{
f[i%2][1] = f[i-1][1]+a[i];
}/*initializing over*/
// cout<<"/*initializing over*/"<<endl;
for(q=2;q<=m;q++)
{
for(p=q;p<=q+(n-m);p++)
{ sum=0;
temp2 = 1000000000;
for(i=p-1;i>=q-1;i--)
{
sum+=a[i+1];
temp1 = max(f[i%2][q-1],sum);
temp2 = min(temp2,temp1);
}
f[p%2][q] = temp2;
}
}
cout<<f[n%2][m]<<endl;
}
long min(const long &p,const long &q)
{
return p<q?p:q;
}
long max(const long &p,const long &q)
{
return p<q?q:p;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator