Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我简直要崩溃了

Posted by mato_no1 at 2011-01-28 22:11:28 on Problem 2531
交暴搜都能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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator