Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
149766 梁乃元 合并石子1 C++ 通过 100 0 MS 356 KB 628 2024-05-29 13:22:41

Tests(5/5):


# include <bits/stdc++.h> using namespace std ; int a [101] , g [101] [101] , dp [101] [101] ; int main ( ) { int n ; cin >> n ; for ( int i = 1 ; i <= n ; i ++ ) { cin >> a [i] ; } for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = i ; j <= n ; j ++ ) { g [i] [j] = g [i] [j - 1] + a [j] ; } } for ( int s = 2 ; s <= n ; s ++ ) { for ( int i = 1 , j = s ; j <= n ; i ++ , j ++ ) { dp [i] [j] = 1 << 30 ; for ( int k = i ; k < j ; k ++ ) dp [i] [j ] = min ( dp [i] [j] , dp [i] [k] + dp [k + 1] [j] + g [i] [j] ) ; } } cout << dp [1] [n] << endl ; return 0 ; }


测评信息: