From f920a379567b0c21e0be73cb8ecc964973063adb Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Thu, 1 Sep 2016 20:22:43 +0800 Subject: [PATCH] Create 2531_martin31hao.cpp From http://blog.csdn.net/martin31hao/article/details/8098302 --- POJ/2531_martin31hao.cpp | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 POJ/2531_martin31hao.cpp diff --git a/POJ/2531_martin31hao.cpp b/POJ/2531_martin31hao.cpp new file mode 100644 index 0000000..91cdb70 --- /dev/null +++ b/POJ/2531_martin31hao.cpp @@ -0,0 +1,45 @@ +#include +#include +using namespace std; + +const int maxn = 30; +int n, ans; +int a[maxn][maxn]; +int dep[maxn]; + +void dfs(int id, int data) +{ + dep[id] = 1; + int tmp = data; + for(int i = 1; i <= n; i ++) + { + if(dep[i] == 0) + tmp += a[i][id]; + else + tmp -= a[i][id]; + } + if(ans < tmp) + ans = tmp; + for(int i = id + 1; i <= n; i ++) + { + if(tmp > data) + { + dfs(i, tmp); + dep[i] = 0; + } + } +} + +int main() +{ + while(~scanf("%d", &n)) + { + for(int i = 1; i <= n; i ++) + for(int j = 1; j <= n; j ++) + scanf("%d", &a[i][j]); + memset(dep, 0, sizeof(dep)); + ans = 0; + dfs(1, 0); + printf("%d\n", ans); + } +}