QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#450862#6821. Another A+B ProblemPetroTarnavskyi#RE 0ms0kbC++201.6kb2024-06-22 18:52:132024-06-22 18:52:14

Judging History

你现在查看的是最新测评结果

  • [2024-06-22 18:52:14]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-06-22 18:52:13]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int N = 301;
db dpT[N][N][N];

int n;
db dp(int path, int edge, int isol)
{
	if(path < 0 || edge < 0 || isol < 0)
		return 0;
	if(path == 0 && isol <= 1)
		return 0;
	if(dpT[path][edge][isol] > -0.5)
		return dpT[path][edge][isol];
	
	int sum = 0;
	
	db res = n * n;
	
	res += isol * (isol - 1) * dp(path, edge + 1, isol - 2);
	sum += isol * (isol - 1);

	res += 4 * isol * edge * dp(path + 1, edge - 1, isol - 1);
	sum += 4 * isol * edge; 

	res += 4 * isol * path * dp(path, edge, isol - 1);
	sum += 4 * isol * path;

	res += 4 * edge * (edge - 1) * dp(path + 1, edge - 2, isol);
	sum += 4 * edge * (edge - 1);

	res += 4 * path * edge * dp(path, edge - 1, isol);
	sum += 4 * path * edge;

	res += 4 * path * (path - 1) * dp(path - 1, edge, isol);
	sum += 4 * path * (path - 1);

	res += 2 * path * dp(path - 1, edge, isol);
	sum += 2 * path;
	
	assert(0 < sum && sum <= n * n - 2 * n);
	return dpT[path][edge][isol] = res / sum; 
}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	FOR(i, 0, N)
		FOR(j, 0, N)
			FOR(k, 0, N)
				dpT[i][j][k] = -1;
			
	cin >> n;
	cout << fixed << setprecision(9) << dp(0, 0, n) << "\n";
	
	
	
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

40+11=51
PBGPPGGB

output:


result: