Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
直接暴搜,未做任何优化 125ms。。。数据有点弱#include <iostream> #include <cstdio> #include <cstring> using namespace std; int c[22][22], n, ans, set[22]; void DFS(int id, int sum) { int i; set[id] = 1; for (i = 0; i < n; i++) { if (set[i] == 1) sum -= c[id][i]; else sum += c[id][i]; } if (sum > ans) ans = sum; for (i = id+1; i < n; i++) { DFS(i, sum); set[i] = 0; } } int main() { int i, j; scanf ("%d", &n); for (i = 0; i < n; i++) for (j = 0; j < n; j++) scanf ("%d", &c[i][j]); memset (set, 0, sizeof (set)); ans = 0; DFS(0, 0); printf ("%d\n", ans); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator