zoukankan      html  css  js  c++  java
  • 【JZOJ5263】分手是祝愿

    Description

    Pic

    请注意本题的数据范围。

    Input

    Output

    Sample Input

    2
    2
    15 19
    3
    30 40 20

    Sample Output

    285
    2600

    Hint

    数据范围:
    30% n<=9
    100% n,a<=100, T<=5

    Source

    动态规划 /DFS /分治

    题解:

      区间DP裸题,注意a可以等于100.

    代码:

      

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cmath>
    #include <iostream>
    #define MAXN 1000
    #define ll long long
    #define mod 100
    using namespace std;
    ll a[MAXN],b[MAXN][MAXN],dp[MAXN][MAXN],num[MAXN][MAXN];
    int n;
    
    ll getit(int x,int y){
        ll ans=0;
        if(x>y) swap(x,y);
        if(y-x==0) return a[x];
        for(int i=x;i<=y;i++) ans=ans+a[i],ans%=mod;
        return ans;
    }
    
    void pre(){
        memset(num,0,sizeof(num));
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++){
                num[i][j]=num[j][i]=getit(i,j);
            }
    }
    
    ll DP(int l,int r){
        if(r-l+1==1) return 0;
        if(l>r) return 1ll<<50;
        if(b[l][r]) return dp[l][r];
        b[l][r]=1;
        for(int k=l;k<=r;k++){
            ll ret=1ll<<60;
            ret=DP(l,k)+DP(k+1,r)+num[l][k]*num[k+1][r];
            dp[l][r]=min(dp[l][r],ret);
        }
        return dp[l][r];
    }
    
    void work(){
        cin>>n;
        for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
        pre();
        memset(dp,37,sizeof(dp));
        memset(b,0,sizeof(b));
        printf("%lld
    ",DP(1,n));
    }
    
    int main()
    {
        int t;cin>>t;
        while(t--){
            work();
        }
        return 0;
    }
  • 相关阅读:
    js 根据屏幕大小调用不同的css文件
    centos U盘安装查看名称
    gmail只能收,不能发解决
    pytty秘钥登陆
    GCP 免密钥登陆
    iredmail安装资料整理
    centos修改本地hostname(主机名)
    chmod 774
    centos 环境部署
    epel更新源
  • 原文地址:https://www.cnblogs.com/renjianshige/p/9657566.html
Copyright © 2011-2022 走看看