Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: mydKN

Problemset: ดีกค์เวิร์ด

Language: cpp

Time: 0.002 second

Submitted On: 2026-03-10 17:35:08

#include <bits/stdc++.h>

using namespace std;

const int maxn = 25;

int n;
int x, y;
int dp[maxn][maxn], cnt[maxn][maxn];
int res;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n;
	char a, b;
	cin >> a >> b;
	x = a - 'A' + 1;
	y = b - 'A' + 1;
	int nn = 2*n;
	cnt[0][0] = 1;
	dp[0][0] = 0;
	for(int i=1;i<=nn;++i){
		for(int j=(i+1)/2;j<=min(i, n);++j){
			if(cnt[i-1][j-1]){
				dp[i][j] += dp[i-1][j-1] + cnt[i-1][j-1]*i*x;
				cnt[i][j] += cnt[i-1][j-1];
			}
			if(cnt[i-1][j]){
				dp[i][j] += dp[i-1][j] + cnt[i-1][j]*i*y;
				cnt[i][j] += cnt[i-1][j];
			}
		}
	}
	cout << dp[nn][n];
}