Manioc

internet

Apr 17th, 2019
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define MAX 1007
  3. #define INF 1e9 + 7
  4. #define make_pair mp
  5.  
  6. using namespace std;
  7. typedef long long ll;
  8. typedef pair<int,int> pii;
  9.  
  10. int arr[MAX], dp[MAX][MAX], pre[MAX][MAX], sum[MAX][MAX];
  11. int main(){
  12.     int n; cin >> n;
  13.     for(int i = 1 ; i <= n; i++) cin >> arr[i];
  14.  
  15.     for(int i = 1; i <= n; i++){
  16.         for(int j = 1; j <= n; j++) {
  17.             pre[i][j] = arr[j]*abs(j-i);
  18.             sum[i][j] += pre[i][j] + sum[i][j-1];
  19.         }
  20.     }
  21.  
  22.     for(int i = 1; i <= n; i++){
  23.         for(int j = 1; j <= n; j++) cout <<  pre[i][j] << " ";
  24.         cout << endl;
  25.     }
  26.     cout << endl;
  27.     for(int i = 1; i <= n; i++){
  28.         for(int j = 1; j <= n; j++) dp[i][j] = INF;
  29.     }
  30.  
  31.     for(int i = 1; i <= n; i++){
  32.         for(int j = 1; j <= n; j++) cout << sum[i][j] << " ";
  33.         cout << endl;
  34.     }
  35.     cout << endl;
  36.     for(int i = 1; i <= n; i++){
  37.         dp[i][1] = sum[i][n];
  38.         for(int j = 0; j < i; j++){
  39.             for(int k = 2; k <= n; k++){
  40.                 dp[i][k] = min(dp[j][k-1]-sum[j][n]+sum[j][j] + sum[j][(j+i)/2]- sum[j][j] + sum[i][n] - sum[i][(j+i+1)/2], dp[i][k]);
  41.             }
  42.         }
  43.     }
  44.  
  45.     for(int i = 1; i <= n; i++){
  46.         for(int j = 1; j <= n; j++) cout <<  dp[i][j] << " ";
  47.         cout << endl;
  48.     }
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment