标签:ios void efi code pac describe combine can exce
Input
Output
Sample Input
1 100 3 3 4 3 4 1 1 1 1 0
Sample Output
0 17 8
1 #include <stdio.h> 2 #include <iostream> 3 #include <cstring> 4 #include <algorithm> 5 #define MAX 55555 6 using namespace std; 7 int a[MAX],n,num,result; 8 void combine(int k) 9 { 10 int i,j; 11 int temp=a[k]+a[k-1]; 12 result+=temp; 13 for(i=k;i<num-1;i++) 14 a[i]=a[i+1]; 15 num--; 16 for(j=k-1;j>0&&a[j-1]<temp;j--) 17 a[j]=a[j-1]; 18 a[j]=temp; 19 while(j>=2&&a[j]>=a[j-2]) 20 { 21 int d=num-j; 22 combine(j-1); 23 j=num-d; 24 } 25 } 26 int main() 27 { 28 int i; 29 while(scanf("%d",&n)&&n){ 30 if(n==0) return 0; 31 for(i=0;i<n;i++) 32 scanf("%d",&a[i]); 33 num=1; 34 result=0; 35 for(i=1;i<n;i++){ 36 a[num++]=a[i]; 37 while(num>=3&&a[num-3]<=a[num-1]) 38 combine(num-2); 39 } 40 while(num>1) combine(num-1); 41 printf("%d\n",result); 42 } 43 return 0; 44 }
POJ 1738:An old Stone Game 石子归并 (GarsiaWachs算法)
标签:ios void efi code pac describe combine can exce
原文地址:http://www.cnblogs.com/shixinzei/p/7243286.html