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 |
谢谢,我AC了In Reply To:增加水题ac人数。。。 Posted by:zsgkfeng at 2009-06-11 14:37:00 > #include<cstdio> > #include<iostream> > #include<algorithm> > #define fo(i,u,d) for(int i=u;i<=d;i++) > using namespace std; > int n,m,a[11000],f[11000],ca; > void init(){ > cin>>m; > cin>>n; > fo(i,1,n)cin>>a[i]; > } > void work(){ > f[0]=0; > fo(i,1,n){ > f[i]=1000000000; > int j=i; > int sum=0; > while ((j>0)&&(sum+a[j]<=m)){ > sum=sum+a[j]; > j--; > if (f[j]+(m-sum)*(m-sum)<f[i])f[i]=f[j]+(m-sum)*(m-sum); > sum++; > } > } > cout<<f[n]<<endl; > } > int main(){ > > for(cin>>ca;ca;ca--){ > init(); > work(); > } > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator