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);
            add(sum[j], dp[i][j]);
        }
    }
    int ans = 0;
    for(int i = 0; i = n; i++) add(ans, dp[i][m]);
    printf("%d\n", ans);
    return 0;
}

/*
*/

 

转载于:https://www.cnblogs.com/CJLHY/p/11069650.html

最新回复(0)
/jishuvqebhn_2FzLNIhm45IIpg_2B3UJFvmT1Lfy_2BaunlAA_3D_3D4794949
8 简首页