Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

增加水题ac人数。。。

Posted by zsgkfeng at 2009-06-11 14:37:00 on Problem 3390
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator