- 最后登录
- 2016-6-29
- 在线时间
- 128 小时
- 阅读权限
- 10
- 注册时间
- 2008-4-30
- 积分
- 171
- 帖子
- 132
- 精华
- 0
- UID
- 30495
- 性别
- 保密
- 积分
- 171
- 帖子
- 132
- 精华
- 0
- UID
- 30495
- 性别
- 保密
|
我贴个伪码- input n
- sum( 0 ) := 0
- for i := 1 to n
- begin
- input a( i )
- f( i, i ) := a( i )
- sum( i ) := sum( i - 1 ) + a( i )
- end
- for i := 1 to n
- for j := 1 to n
- f( j, i + j ) = sum( i + j ) - sum( j - 1 ) - min( f( j + 1, i + j ), f( j, i + j - 1 ) )
- print f( 1, n ), sum( n ) - f( 1, n ) //f( 1, n )是S甲,sum( n ) - f( 1, n )是S乙
- //下面开始输出每个数第几次被取走
- start := 1
- end := n
- for i := 1 to n
- begin
- if f( start + 1, end ) < f( start, end - 1 )
- begin
- p( start ) := i
- start := start + 1
- end
- else
- begin
- p( end ) := i
- end := end - 1
- end
- end
- for i := 1 to n
- print p( i )
复制代码 |
|