zoukankan      html  css  js  c++  java
  • hdu 5900 QSC and Master 区间dp

    QSC and Master

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)


    Problem Description
    Every school has some legends, Northeastern University is the same.

    Enter from the north gate of Northeastern University,You are facing the main building of Northeastern University.Ninety-nine percent of the students have not been there,It is said that there is a monster in it.

    QSCI am a curious NEU_ACMer,This is the story he told us.

    It’s a certain period,QSCI am in a dark night, secretly sneaked into the East Building,hope to see the master.After a serious search,He finally saw the little master in a dark corner. The master said:

    “You and I, we're interfacing.please solve my little puzzle!

    There are N pairs of numbers,Each pair consists of a key and a value,Now you need to move out some of the pairs to get the score.You can move out two continuous pairs,if and only if their keys are non coprime(their gcd is not one).The final score you get is the sum of all pair’s value which be moved out. May I ask how many points you can get the most?

    The answer you give is directly related to your final exam results~The young man~”

    QSC is very sad when he told the story,He failed his linear algebra that year because he didn't work out the puzzle.

    Could you solve this puzzle?

    (Data range:1<=N<=300
    1<=Ai.key<=1,000,000,000
    0<Ai.value<=1,000,000,000)
     
    Input
    First line contains a integer T,means there are T(1≤T≤10) test case。

      Each test case start with one integer N . Next line contains N integers,means Ai.key.Next line contains N integers,means Ai.value.
     
    Output
    For each test case,output the max score you could get in a line.
     
    Sample Input
    3 3 1 2 3 1 1 1 3 1 2 4 1 1 1 4 1 3 4 3 1 1 1 1
     
    Sample Output
    0 2 0
     
    Source
    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define pi (4*atan(1.0))
    const int N=1e3+10,M=1e6+1010,inf=1e9+10,mod=1e9+7;
    const ll INF=1e18+10;
    ll dp[N][N];
    ll a[N];
    ll b[N];
    ll sum[N];
    int main()
    {
        int T;
        scanf("%d",&T);
        while(T--)
        {
            memset(dp,0,sizeof(dp));
            memset(sum,0,sizeof(sum));
            int n;
            scanf("%d",&n);
            for(int i=1;i<=n;i++)
            scanf("%lld",&a[i]);
            for(int i=1;i<=n;i++)
            scanf("%lld",&b[i]),sum[i]=sum[i-1]+b[i];
            for(int i=2;i<=n;i++)
            {
                for(int t=1;t+i-1<=n;t++)
                {
                    if(__gcd(a[t],a[t+i-1])!=1&&sum[t+i-2]-sum[t]==dp[t+1][t+i-2])
                    {
                        dp[t][t+i-1]=sum[t+i-1]-sum[t-1];
                        continue;
                    }
                    for(int j=t;j<=t+i-2;j++)
                    {
                        dp[t][t+i-1]=max(dp[t][t+i-1],dp[t][j]+dp[j+1][t+i-1]);
                    }
                }
            }
            printf("%lld
    ",dp[1][n]);
        }
        return 0;
    }
  • 相关阅读:
    高仿富途牛牛-组件化(三)-界面美化
    高仿富途牛牛-组件化(二)-磁力吸附
    高仿富途牛牛-组件化(一)-支持页签拖拽、增删、小工具
    Cef3 学习资料
    QCustomplot使用分享(八) 绘制图表-加载cvs文件
    Electron桌面应用:环境搭建
    Qt疑难问题-模态窗口父类被析构
    Qt线程实现分析-moveToThread vs 继承
    基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系。
    asp.net中的ListBox控件添加双击事件
  • 原文地址:https://www.cnblogs.com/jhz033/p/5893985.html
Copyright © 2011-2022 走看看