-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaoj0145.cpp
More file actions
51 lines (50 loc) · 1.04 KB
/
aoj0145.cpp
File metadata and controls
51 lines (50 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
#define MAX 100
const int INF = 1<<28;
int main() {
int n, dp[100][100] = {}, c[100][2];
cin >> n;
REP(i,n)
cin >> c[i][0] >> c[i][1];
REP(i, 100) REP(j, 100) {
if(i == j) continue;
dp[i][j] = INF;
}
FOR(i, 1, n)
REP(j, n-i)
FOR(k, j, j+i) {
dp[j][j+i] = min(dp[j][j+i], dp[j][k] + dp[k+1][j+i] + c[j][0] * c[k][1] * c[k+1][0] * c[j+i][1]);
cout << "i " << i << " j " << j << " k " << k << ' ' << dp[j][j+i] << endl;
}
REP(i, 10) {
REP(j, 10) {
if(dp[i][j] == INF)
cout << "INF ";
else
cout << dp[i][j] << ' ';
}
cout << endl;
}
cout << dp[0][n-1] << endl;
return 0;
}