QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#369754#2827. AutobiographyPetroTarnavskyi#WA 0ms3792kbC++201.3kb2024-03-28 17:32:162024-03-28 17:32:16

Judging History

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

  • [2024-03-28 17:32:16]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3792kb
  • [2024-03-28 17:32:16]
  • 提交

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 = 51;

int n;
int p[N];
LL dp[N][N][N][N][2];

LL f(int i, int j, int l, int r, int k)
{
	if (i > j)
	{
		assert(k == 0);
		return 1;
	}
	if (l > r)
	{
		return k == 0 ? 1 : 0;
	}
	LL& res = dp[i][j][l][r][k];
	if (res != -1)
		return res;
	res = 0;
	if (l <= p[i] && p[i] <= r)
	{
		res = f(i + 1, j, l, p[i] - 1, 0);
		FOR(pos, i + 1, j + 1)
		{
			res += f(i + 1, pos - 1, l, p[i] - 1, 0) * f(pos, j, p[i] + 1, r, 1);
		}
	}
	if (k == 0)
		res += f(i + 1, j, l, r, 0);
	return res;
	
}

void solve()
{
	FOR(i, 0, n)
	{
		cin >> p[i];
		p[i]--;
	}
	FOR(i, 0, n)
		FOR(j, 0, n)
			FOR(l, 0, n)
				FOR(r, 0, n)
					FOR(k, 0, 2)
						dp[i][j][l][r][k] = -1;
	cout << f(0, n - 1, 0, n - 1, 0) - 1 << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	while (cin >> n)
		solve();
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3792kb

input:

5 4
bbobo
1 3
2 3
3 4
4 5
4 6
bobo
1 2
1 3
1 4
2 3
2 4
3 4
4 0
bobo

output:

1

result:

wrong answer 1st lines differ - expected: '2', found: '1'