首页 > 其他 > 详细

【找规律】【递归】XVII Open Cup named after E.V. Pankratiev Stage 4: Grand Prix of SPb, Sunday, Octorber 9, 2016 Problem F. Doubling

时间:2017-09-28 18:55:13      阅读:445      评论:0      收藏:0      [点我收藏+]

题意:

技术分享

给你一个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;
}

【找规律】【递归】XVII Open Cup named after E.V. Pankratiev Stage 4: Grand Prix of SPb, Sunday, Octorber 9, 2016 Problem F. Doubling

原文:http://www.cnblogs.com/autsky-jadek/p/7607995.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!