nyoj_746 整数划分(四)
来源:互联网 发布:电脑版淘宝是哪个版本 编辑:程序博客网 时间:2024/06/05 05:06
题目链接: http://acm.nyist.net/JudgeOnline/problem.php?pid=746
分析:
dp[i][j] : 表示在区间 [0,i] 插入 j 个乘号可以得到的最大值
a[i][j] : 表示区间 [i,j] 所形成的数
则: dp[i][j]=max(dp[k][j-1]*a[k+1][i])
代码:
#include<cstdlib>
#include<string>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<ctime>
#include<cstdio>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
int main()
{
int tt;
scanf("%d",&tt);
ll dp[25][25];
ll a[25][25];
char ss[25];
while(tt--)
{
int m;
scanf("%s%d",ss,&m);
memset(dp,0,sizeof(dp));
memset(a,0,sizeof(a));
m--;
int len = strlen(ss);
for(int i=0;i<len;i++)
{
a[i][i] = ss[i]-'0';
// cout<<a[i][i]<<endl;
for(int j=i+1;j<len;j++)
{
a[i][j] = a[i][j-1] * 10 + ss[j]-'0';
// cout<<a[i][j]<<endl;
}
}
for(int i=0;i<len;i++)
{
dp[i][0]=a[0][i];
}
for(int j=1;j<=m;j++)
{
for(int i=j;i<len;i++)
{
for(int k=0;k<i;k++)
{
dp[i][j]=max(dp[i][j],dp[k][j-1]*a[k+1][i]);
}
}
}
printf("%lld\n",dp[len-1][m]);
}
return 0;
}
- nyoj_746 整数划分(四)
- 整数划分(四)
- 整数划分(四)
- 整数划分(四)
- 整数划分(四)
- nyoj746整数划分(四)
- NYOJ746 整数划分(四)
- nyoj746 整数划分(四)
- nyoj746 整数划分(四)
- 整数划分(四)+经典问题
- NYOJ746——整数划分(四)
- nyoj746整数划分(四)【区间dp】
- NYOJ 746 整数划分(四)
- NYOJ746——整数划分(四)
- nyoj746整数划分(四)【区间dp】
- nyoj746 整数划分(四)【区间dp】
- NYOJ-746整数划分(四)
- 整数划分四
- Python 数据处理:Pandas 模块的 12 种实用技巧
- HTML5编程(任务二 零基础HTML及CSS编码)(20160909-0040)
- JS中关于clientWidth offsetWidth scrollWidth 等的含义
- 优化3D分子构型的方法有哪些
- 终极讲解:java中HashMap,LinkedHashMap,TreeMap,HashTable的区别
- nyoj_746 整数划分(四)
- 设计模式学习(七)————工厂方法模式
- 网易校招笔试-暗黑串
- win10 程序最小化不在任务栏了?在左下角
- Maven项目生成idea项目文件
- Qt 窗口置顶
- Java判断是否为手机端访问
- 分组加密的四种模式
- 设计模式学习(八)————原型模式