1.	统计子序列数
[问题描述]
现有一个长度为 n、互不相同的正整数序列, 请你求出该序列中所有递增和递减子序列的
数目。
例如:整数序列 (7,  4,  6,  9,  8,  3, 5, 2, 1 ) ,可以分为  (7,  4), (4,  6,  9 ), (9, 8, 3),(3, 5), (5, 2, 1)这些递增和递减子序列,即:子序列的数目为 5。
【程序清单】
program sx201606;
  var n,i,s:integer;
  d:array[l..100] of integer;
begin
  readln(n);
  for i:=1 to n do read( d[i] );
    s:= 1 ;
	for i:=2 to n-1 do
	  if  (d[i]-d[i-1] )* (d[i]-d[i+1]) >0 then inc(s) ;
   writeln(s);
end.
			
				
							  
							 
				
			
		 	
			
		
			
							 
				2.	合并石子
[ 问题描述 ]
今天课间的时候,小明同学在学校的操场上发现了 n 堆大小不一的小石子,小明决定将 它们合并成一堆 , 但现在小明思考着这样一个问题:如何消耗最少的体力,把这 n堆小石子合并成一堆?现已知合并所消耗的体力等于每次合并两堆小石子的重量之和 , 每次合并,他会把其中的两堆小右子合并到一起, n堆小石子经过 n-ii 合并之后就只剩一堆了。
比如,n=3时表示共有 3 堆每堆重量分别是么 2、1、9。一种合并方案是 2 和 9  合并,新堆重量是 11,耗费体力为 11;接着 11 与 1 合并新堆重量是 12,耗费体力为 12,  因此总消耗体力是 11+12=23。另一种方案是 12,新堆重量是 3,耗费体力为 3,  接着 3 和 9 合并,新堆重量是 12,耗费体力为 12,因此总消耗体力是 3+12=15。可以证明 这样合并就是最少耗费体 3 的方法。
var i, sum, n: integer;
  a:array[1..100]of integer;
procedure sort(x:integer);
var i, j, temp: integer ;
begin
    for i:= x  to  n-1 do
    for j:=n downto  i+1   do
        if  a[j]<a[j-1]  then
          begin
             temp:=a[j]; a[j] :=a[j-1]; a[j-1] :=temp;
          end ;
end;
begin
  readln(n);
  for i:=1 to n do read (a[i]);
  sum:=0;
  sort(1);
  for i:=1 to n-1 do
  begin
    a[i+1]:=a[i]+a[i+1];
	sum:= sum+a[i+1] ;
	 sort(i+1) ;
  end ;
  writeln(sum);
end.