【找规律】【递归】XVII Open Cup named after E.V. Pankratiev Stage 4: Grand Prix of SPb, Sunday, Octorber 9, 2016 Problem F. Doubling
2024-09-24 20:46:44
题意:
给你一个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;
}
最新文章
- Fragment:关于Avoid non-default constructors in fragments的错误
- ruby日记1
- Java基础之集合框架——使用真的的链表LinkedList<;>;(TryPolyLine)
- wpf 在引用外部的资源字典
- 本地虚拟机挂载windows共享目录搭建开发环境
- java.imageIo给图片添加水印
- SQL Server触发器以及如何在SQL Server Manager中调试触发器
- 【POJ3468】【zkw线段树】A Simple Problem with Integers
- 【OpenGL游戏开发之二】OpenGL常用API
- 基于visual Studio2013解决面试题之1309求子集
- 关于“类不能支持Automation操作”错误的解决方法
- 阿里云centos7成功安装和启动nginx,但是外网访问不了的解决方案
- 单片机AT和STC区别
- 如何使用Visual Studio 2017调试.net库源代码
- Redis源码学习-Master&;Slave的命令交互
- 获取HttpServletRequest请求Body中的内容
- 【转】ubuntu 打开命令行窗口的方法
- java.io.IOException: java.sql.SQLException: ORA-01502: index &#39;BTO.PK_xxxxx&#39; or partition of such index is in unusable state
- 基于request.getAttribute与request.getParameter的区别详解
- Java的工厂模式(三)