题目:传送门

题目描述

This is a very simple problem, just like previous one.
You are given a postive integer n, and you need to divide this integer into m pieces. Then multiply the m pieces together. There are many way to do this. But shadow95 want to know the maximum result you can get.

输入

 First line is a postive integer t, means there are T test cases.

Following T lines, each line there are two integer n, m. (0<=n<=10^18, 0 < m < log10(n))

输出

 Output the maximum result you can get.

示例输入

1
123 2

示例输出

36

提示

You can divide "123" to "12" and "3".
Then the maximum result is 12*3=36.
 
题意很简单,但是我就是个渣渣,dp的题在比赛里从来没有A过,果断还是看了题解,也只是会了这个类型,其他类型的区间dp果断还是不会,果断不能举一反三啊。
 
代码如下:
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
typedef long long ll;
using namespace std;
#define mod 1000000007
int m,l;
char s[];//局部变量与全局变量求字符串长度完全不同
ll a[][],dp[][];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s",s+);
scanf("%d",&m);
l=strlen(s+);
memset(a,,sizeof(a));
if(m==||m==)
{
printf("%s\n",s+);
continue;
}
for(int i=;i<=l;i++)
{
for(int j=i;j<=l;j++)
{
a[i][j]=a[i][j-]*+(s[j]-'');
}
}
memset(dp,,sizeof(dp));
for(int i=;i<=l;i++)
dp[i][]=a[][i];
for(int j=;j<=m;j++)
{
for(int i=j;i<=l;i++)
{
for(int k=;k<i;k++)
{
dp[i][j]=max(dp[i][j],dp[k][j-]*a[k+][i]);
}
}
}
printf("%lld\n",dp[l][m]);
}
return ;
}
 

最新文章

  1. javascript函数的几种写法集合
  2. 计算c字符的长度,保证不超过2^30
  3. unity安卓和IOS读写目录
  4. Codeforces gym 100685 E. Epic Fail of a Genie 贪心
  5. [置顶] 用mootools实现checkbox全选功能
  6. 实验楼 -- (Linux)
  7. ccflow表机构与运行机制(二次开发必看)
  8. C. Painting the Fence
  9. 爬虫_拉勾网(selenium)
  10. HDFS 读写数据流程
  11. Elasticsearch--&gt;Get Started--&gt; Exploring Your Data
  12. Python中的print、input函数以及Python中交换两个变量解析
  13. maven打包到私服,打的是war包,好郁闷
  14. GitHub多人协作简明教程
  15. 记一次socket_create()函数耗时异常记录
  16. (转存 作者未知)深入理解HTML协议
  17. Data Base Oracle 常用命令
  18. 游戏2:HTML5制作网页游戏看看你有多色--createjs
  19. 阿里云CentOS环境下tomcat启动超级慢的解决方案
  20. Machine Learning笔记整理 ------ (四)线性模型

热门文章

  1. Spring MVC学习之三:处理方法返回值的可选类型
  2. 29Spring_Autowriter的一些疑惑(很重要)
  3. 【mysql】windows7 安装 Mysql
  4. mysql远程连接授权
  5. jQuery实现高亮显示网页关键词的方法
  6. python3----scrapy(笔记)
  7. MP 及OMP算法解析
  8. 【BZOJ4598】[Sdoi2016]模式字符串 树分治+hash
  9. angular中的动画效果
  10. git--简单操作