zoukankan      html  css  js  c++  java
  • Codeforces 360C Levko and Strings dp (看题解)

    Levko and Strings

    感觉怎么复杂度都不对。。

    没想到暴力转移复杂度是对的, 好菜啊。

    #include<bits/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 pair<LL, LL>
    #define PLI pair<LL, int>
    #define PII pair<int, 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);
    
    template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;}
    template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < 0) a += mod;}
    template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;}
    template<class 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
    ", ans);
        return 0;
    }
    
    /*
    */
  • 相关阅读:
    Sqli-labs Less-47 order by后的注入
    Sqli-labs Less-46 order by后的注入
    Sqli-labs Background-9 order by后的injection
    Sqli-labs Less-45 堆叠注入
    jsp,servlet知识点
    jsp页面编码不统一可能会出问题
    jsp页面找不到,jsp页面乱码
    BZOJ 2843: 极地旅行社 lct splay
    2018/3/23 省选模拟赛
    bzoj 4573: [Zjoi2016]大森林 lct splay
  • 原文地址:https://www.cnblogs.com/CJLHY/p/11069650.html
Copyright © 2011-2022 走看看