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

1700 crossing river

Posted by TXJ at 2008-09-14 08:52:17
这怎么错了,思路,分n=1 n=2 n=3 n>=4 当n>=4时,有两种选法。 测试是对的,提交就是WA,谁能给个测试用例
#include<stdio.h>
int p[1001];
int total=0;
int time(int n ){
int m=n;
if(n==1)
return(total+=p[0]);
else if(n==2)
return(total+=p[1]);
else if(n==3)
return(total+=p[0]+p[1]+p[2]);
else{
if(2*p[1]>=p[0]+p[m-1])
{total+=2*p[0]+p[m-2]+p[m-1];
m=m-2;
time(m);}
else{
total+=p[0]+p[m-1]+2*p[1];
m=m-2;
time(m);} }
return total;
  }
int main(){
int n ,i,t,j,temp;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&p);
for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
        if(p>p[j]){
        temp=p;p=p[j];p[j]=temp;}}}
total=0;
printf("%d\n",time(n));
}}

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