标签:ide 四边形不等式 first several hid ons elf ble scanf
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 2665 Accepted Submission(s): 1074
1 #include <iostream> 2 #include <fstream> 3 #include <sstream> 4 #include <cstdlib> 5 #include <cstdio> 6 #include <cmath> 7 #include <string> 8 #include <cstring> 9 #include <algorithm> 10 #include <queue> 11 #include <stack> 12 #include <vector> 13 #include <set> 14 #include <map> 15 #include <list> 16 #include <iomanip> 17 #include <cctype> 18 #include <cassert> 19 #include <bitset> 20 #include <ctime> 21 22 using namespace std; 23 24 #define pau system("pause") 25 #define ll long long 26 #define pii pair<int, int> 27 #define pb push_back 28 #define mp make_pair 29 #define mp make_pair 30 #define pli pair<ll, int> 31 #define clr(a, x) memset(a, x, sizeof(a) 32 33 const double pi = acos(-1.0); 34 const int INF = 0x3f3f3f3f; 35 const int MOD = 1e9 + 7; 36 const double EPS = 1e-9; 37 38 /* 39 #include <ext/pb_ds/assoc_container.hpp> 40 #include <ext/pb_ds/tree_policy.hpp> 41 using namespace __gnu_pbds; 42 #define TREE tree<pli, null_type, greater<pli>, rb_tree_tag, tree_order_statistics_node_update> 43 TREE T; 44 */ 45 46 int n, a[2015], dp[2015][2015], p[2015][2015], sum[2015]; 47 int main() { 48 while (~scanf("%d", &n)) { 49 for (int i = 1; i <= n; ++i) { 50 scanf("%d", &a[i]); 51 a[i + n] = a[i]; 52 } 53 for (int i = 1; i <= n << 1; ++i) { 54 sum[i] = sum[i - 1] + a[i]; 55 } 56 for (int i = 1; i <= n << 1; ++i) { 57 p[i][i] = i; 58 dp[i][i] = 0; 59 } 60 for (int l = 2; l <= n; ++l) { 61 for (int i = 1; i <= 2 * n - l + 1; ++i) { 62 int j = i + l - 1; 63 dp[i][j] = INF; 64 for (int k = p[i][j - 1]; k <= p[i + 1][j]; ++k) { 65 if (dp[i][k] + dp[k + 1][j] < dp[i][j]) { 66 dp[i][j] = dp[i][k] + dp[k + 1][j]; 67 p[i][j] = k; 68 } 69 } 70 dp[i][j] += sum[j] - sum[i - 1]; 71 } 72 } 73 int ans = INF; 74 for (int i = 1; i <= n; ++i) { 75 ans = min(ans, dp[i][i + n - 1]); 76 } 77 printf("%d\n", ans); 78 } 79 return 0; 80 }
标签:ide 四边形不等式 first several hid ons elf ble scanf
原文地址:https://www.cnblogs.com/BIGTOM/p/9694562.html