zoukankan      html  css  js  c++  java
  • NYOJ

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=746

    要求对一个n的整数插入m个乘号,求最大结果。

    构造dp:dp[i][j]表示枚举至j时,插入i个乘号的状态。

    那么dp[i][j]=dp[i-1][k]*sum(k+1,j)。

     
    #include <iostream>
    #include <map>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <set>
    #include <cmath>
    
    #define LL long long int
    using namespace std;
    int n;
    LL ap[25][25];
    LL dp[25][25];
    int main()
    {
        int t;
        cin.sync_with_stdio(false);
        cin>>t;
        while(t--)
        {
            string s;
            int num;
            cin>>s>>num;
            for(int i=0;i<s.length();i++)
            {
                LL sum=0;
                for(int j=i;j<s.length();j++)
                {
                    sum*=10;
                    sum+=s[j]-'0';
                    ap[i][j]=sum;
                }
            }
            num--;
            int len=s.length();
            for(int i=0;i<=num;i++)
            {
                for(int j=i;j<len;j++)
                {
                    if(i==0)
                        dp[i][j]=ap[0][j];
                    else
                    {
                        dp[i][j]=-1;
                        for(int k=i-1;k<j;k++)
                            dp[i][j]=max(dp[i][j],dp[i-1][k]*ap[k+1][j]);
                    }
                }
            }
            LL ans=-1;
            for(int i=num;i<len;i++)
                ans=max(ans,dp[num][i]);
            cout<<ans<<endl;
        }
    
        return 0;
    }
            
  • 相关阅读:
    easyui
    applicationContext.xml xxx-servlet.xml
    response ,request编码
    json 处理
    webservice wsdl 生成服务
    springmvc 定时器
    ftp命令和scp命令
    Telnet、FTP、SSH、SFTP、SCP
    mysql 索引
    民科吧 见闻录
  • 原文地址:https://www.cnblogs.com/LukeStepByStep/p/6788821.html
Copyright © 2011-2022 走看看