# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
83307 | fredbr | Mate (COCI18_mate) | C++17 | 2072 ms | 42312 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxm = 30;
const int maxn = 2010;
typedef long long ll;
const ll mod = 1000000007;
ll dp[maxm][maxm][maxn];
ll pchoose[maxn][maxn];
ll choose(ll n, ll k)
{
if (pchoose[n][k] >= 0) return pchoose[n][k];
return pchoose[n][k] = (choose(n-1, k) + choose(n-1, k-1)) % mod;
}
void init()
{
memset(pchoose, -1, maxn*maxn*8);
for (int i = 0; i < maxn; i++) {
pchoose[i][0] = 1;
pchoose[i][i] = 1;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
int n = s.size();
init();
for (int i = 0; i < n-1; i++) {
for (int j = i+1; j < n; j++) {
for (int k = 0; k <= i; k++) {
dp[s[i]-'a'][s[j]-'a'][k+2] += choose(i, k);
dp[s[i]-'a'][s[j]-'a'][k+2] %= mod;
}
}
}
int q;
cin >> q;
while (q--) {
int num;
char a, b;
cin >> num >> a >> b;
cout << dp[a-'a'][b-'a'][num] << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |