题意:

给你一个n,问你R(n)对应的字符串长度最小的是啥。

dp打个表出来,f(i)表示i值对应的字符串的最小长度,发现f(1)=1,f(2)=2,其他的情况下,若是偶数,则恰好在其外面加一对中括号,然后中间填i/2最优,若是奇数,恰好在i-1前面加个1最优。

于是递归输出答案即可。

#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
string work(int x){
if(x==1){
return "1";
}
if(x==2){
return "11";
}
if(x%2==1){
return "1"+work(x-1);
}
else{
return "["+work(x/2)+"]";
}
}
int n;
int main(){
scanf("%d",&n);
cout<<work(n)<<endl;
return 0;
}

最新文章

  1. Fragment:关于Avoid non-default constructors in fragments的错误
  2. ruby日记1
  3. Java基础之集合框架——使用真的的链表LinkedList&lt;&gt;(TryPolyLine)
  4. wpf 在引用外部的资源字典
  5. 本地虚拟机挂载windows共享目录搭建开发环境
  6. java.imageIo给图片添加水印
  7. SQL Server触发器以及如何在SQL Server Manager中调试触发器
  8. 【POJ3468】【zkw线段树】A Simple Problem with Integers
  9. 【OpenGL游戏开发之二】OpenGL常用API
  10. 基于visual Studio2013解决面试题之1309求子集
  11. 关于“类不能支持Automation操作”错误的解决方法
  12. 阿里云centos7成功安装和启动nginx,但是外网访问不了的解决方案
  13. 单片机AT和STC区别
  14. 如何使用Visual Studio 2017调试.net库源代码
  15. Redis源码学习-Master&amp;Slave的命令交互
  16. 获取HttpServletRequest请求Body中的内容
  17. 【转】ubuntu 打开命令行窗口的方法
  18. java.io.IOException: java.sql.SQLException: ORA-01502: index &#39;BTO.PK_xxxxx&#39; or partition of such index is in unusable state
  19. 基于request.getAttribute与request.getParameter的区别详解
  20. Java的工厂模式(三)

热门文章

  1. 转一篇sublime必备的一些插件
  2. jq_常用方法
  3. 主成分分析(PCA)及其在R里的实现
  4. Android控件——Button与ImageButton
  5. iOS 真机调试报错汇总
  6. Leetcode 之Count and Say(35)
  7. C# 实现动态添加列,新增合计行,求和
  8. OpenCL学习笔记(三):OpenCL安装,编程简介与helloworld
  9. 玩转RaspberryPi
  10. 最佳 WordPress 静态缓存插件 WP Super Cache 安装和使用(转)