#include <iostream>
using namespace std;
const int N = 20;
int t1[N], t2[N], n, a[N], b[N], ans = 1000000000;
void dfs(int step)
{
if (step > n)
{
int T1 = 0, T2 = 0;
for (int j = 1; j <= n; j ++ )
{
T1 = T1 + t1[a[j]];
if (T1 < T2) T2 = T2 + t2[a[j]];
else T2 = T1 + t2[a[j]];
}
if (ans > T2) ans = T2;
return;
}
for (int i = 1; i <= n; i ++ )
if (b[i] == 0)
{
b[i] = 1;
a[step] = i;
dfs(step + 1);
b[i] = 0;
}
}
int main(void)
{
cin >> n;
for (int i = 1; i <= n; i ++ )
cin >> t1[i] >> t2[i];
dfs(1);
cout << ans;
return 0;
}
共 4 条回复
@root 五年前我还是个vb都搞不明白的人哈哈哈
2024考古队:报告!发现一篇五年前的帖子,已经汇报给上面了!
独立思考,独立完成,你的能力将会极速上升!
咦~动态数组而已嘛~~