# Codeforces 360C Levko and Stringsdp (看题解）

Levko and Strings

```#includebits/stdc++.h
#define LL long long
#define LD long double
#define ull unsigned long long
#define fi first
#define se second
#define mk make_pair
#define PLL pairLL, LL
#define PLI pairLL, int
#define PII pairint, int
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
#define fio ios::sync_with_stdio(false); cin.tie(0);

using namespace std;

const int N = 2000 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double PI = acos(-1);

templateclass T, class S inline void add(T a, S b) {a += b; if(a = mod) a -= mod;}
templateclass T, class S inline void sub(T a, S b) {a -= b; if(a  0) a += mod;}
templateclass T, class S inline bool chkmax(T a, S b) {return a  b ? a = b, true : false;}
templateclass T, class S inline bool chkmin(T a, S b) {return a  b ? a = b, true : false;}

int n, m;
int dp[N][N];
int sum[N];
char s[N];

int main() {
scanf("%d%d%s", n, m, s + 1);
dp[0][0] = 1;
sum[0] = 1;
for(int i = 1; i = n; i++) {
for(int j = 0; j = m; j++) {
dp[i][j] = 1LL * sum[j] * (s[i] - 'a') % mod;
for(int k = i - 1; k = 0  (i - k) * (n - i + 1) = j; k--)
add(dp[i][j], 1LL * dp[k][j - (i - k) * (n - i + 1)] * ('z' - s[i]) % mod);
}
}
int ans = 0;
for(int i = 0; i = n; i++) add(ans, dp[i][m]);
printf("%d\n", ans);
return 0;
}

/*
*/```

• 03:24
• 03:58
• 1:35:00
• 04:44
• 03:42
• 04:35
• 星秀