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 |
我简直要崩溃了交暴搜都能WA: #include <iostream> #include <stdio.h> #include <string.h> using namespace std; #define re(i, n) for (int i=0; i<n; i++) const int MAXN = 50; int n, a[MAXN][MAXN], res = 0; bool f[MAXN]; void init() { scanf("%d", &n); re(i, n) re(j, n) scanf("%d", &a[i][j]); } void dfs(int v, int sum) { if (v == n) { if (sum > res) res = sum; return; } f[v] = 0; int sum0 = sum; re(i, v) if (f[i]) sum0 += a[i][v]; dfs(v + 1, sum0); f[v] = 1; sum0 = sum; re(i, v) if (!f[i]) sum0 += a[i][v]; dfs(v + 1, sum0); } void solve() { memset(f, 0, n << 2); dfs(1, 0); } void pri() { printf("%d\n", res); } int main(void) { init(); solve(); pri(); return 0; } 然后,随机化,随机30W次还是WA(我RP再差也不至于差到这个地步吧囧): #include <iostream> #include <stdio.h> #include <string.h> using namespace std; #define re(i, n) for (int i=0; i<n; i++) const int MAXN = 50, RN = 300000; int n, a[MAXN][MAXN], res = 0; bool f[MAXN]; void init() { scanf("%d", &n); re(i, n) re(j, n) scanf("%d", &a[i][j]); } void solve() { int s, sum = 0; memset(f, 0, n << 2); re(x, RN) { s = rand() % n; f[s] = !f[s]; re(i, n) if (f[i] == f[s]) sum -= a[i][s]; else sum += a[i][s]; if (sum > res) res = sum; } } void pri() { printf("%d\n", res); } int main(void) { init(); solve(); pri(); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator