`
bcyy
  • 浏览: 1826729 次
文章分类
社区版块
存档分类
最新评论

Timus 1225. Flags Fibonacci的应用

 
阅读更多

On the Day of the Flag of Russia a shop-owner decided to decorate the show-window of his shop with textile stripes of white, blue and red colors. He wants to satisfy the following conditions:
  1. Stripes of the same color cannot be placed next to each other.
  2. A blue stripe must always be placed between a white and a red or between a red and a white one.
Determine the number of the ways to fulfill his wish.
Example.ForN= 3 result is following:
Problem illustration

Input

N, the number of the stripes, 1 ≤N≤ 45.

Output

M, the number of the ways to decorate the shop-window.

Sample

input output
3
4


原来Fibonacci可以这么来使用的,本题的动态规划法应用,大略分析如下:

f(n) = f(n-1) + f(n-2)

when f(n-1)put W and [R,...(n-1)] or R and [W,...(n-1)]

when f(n-2)put R,B and [W,..(n-2)] or W,B and [R,...(n-2)]

Why OR? Because if we do both, then we get repeated flags, so it make a finonacci sequence.

class Flags1225
{
	static const int N = 46;
	long long A[N];
public:
	Flags1225()
	{
		A[0] = 0, A[1] = 2, A[2] = 2, A[3] = 4;
		for (int i = 4; i < N; i++)
		{
			A[i] = A[i-1] + A[i-2];
		}
	}
	void run()
	{
		int a = 0;
		cin>>a;
		cout<<A[a];
	}
};





分享到:
评论

相关推荐

    RegExp.prototype.flags:符合ES6规范的RegExp.prototype.flags垫片

    RegExp.prototype.flags 符合ES6规范的RegExp.prototype.flags填充文件。 如果不可用,请调用其“ shim”方法对RegExp.prototype.flags进行填充。 注意: RegExp#flags需要一个真正的ES5环境-特别是一个带有ES5吸气...

    tensorflow 使用flags定义命令行参数的方法

    tf定义了tf.app.flags,用于支持接受命令行传递参数,相当于接受argv。 import tensorflow as tf #第一个是参数名称,第二个参数是默认值,第三个是参数描述 tf.app.flags.DEFINE_string('str_name', 'def_v_1',...

    java开发opc客户端jar包

    纯java opc客户端需要的utgard 项目中jar包。纯java opc客户端需要的utgard 项目中jar包

    rtl8712_8188_8191_8192SU

    rtl8712_8188_8191_8192SU_usb_linux 系列网卡的linux驱动程序很好很强大

    cin与cout用法

    本文件是对cin和cout一些用法的总结,框图结构,需要用mindjet打开,(同时推介一下mindjet这款工具,很适合代码爱好者总结)。对cin、cout用法迷惑的请进

    使用wireshark抓RTSP, RTP, RTCP网络包

    提供如何使用wireshark进行抓包RTSP, RTP调试,了解RTSP, RTP的协议及客户端与服务端的交互过程,方便大家debug。

    前端项目-currency-flags.zip

    前端项目-currency-flags,货币代码标志。

    css-flags, 只有一个div的世界标志.zip

    css-flags, 只有一个div的世界标志 CSS标志用纯CSS重新创建世界上所有的国旗,每个标志只使用一个 div 。你可以看到它生活在 ...这一侧项目没有真正的世界应用程序,它只是推动我对CSS

    gulp-cli:gulp的命令行界面

    &gt; gulp [flags] &lt; task&gt; &lt; task&gt; ... 自定义元数据 使用gulp -T命令列出任务时,gulp-cli将显示一些根据任务功能定义的自定义元数据。 当前支持的属性: task.description要显示的描述的字符串。 function clean ...

    关于Tensorflow使用CPU报错的解决方式

    如下所示,简单明了,希望能帮助到...tf.app.Flags.DEFINE_boolean(‘clone_on_cpu’,False,’use CPUs to deploy clones.’) 改为: tf.app.Flags.DEFINE_boolean(‘clone_on_cpu’,True,’use CPUs to deploy clones.

    Python库 | feature_flags_client-1.0.13.dev1.tar.gz

    资源分类:Python库 所属语言:Python 资源全名:feature_flags_client-1.0.13.dev1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    emoji-flags, 返回国家代码符号符号标志.zip

    emoji-flags, 返回国家代码符号符号标志 符号标志 返回国家代码符号符号标志安装$ npm install --save emoji-flags用法 var emojiFlags = 要求 ( '

    WindowManager.docx

    整理了Android中WindowManager.LayoutParams.type、WindowManager.LayoutParams.flags、WindowManager.LayoutParams.softInputMode等属性,含注解。

    NTFS Documentation

    Table of Contents 1. Prologue ................................................................................................................... 1. NTFS Documentation Preface ........................

    uCOS-II和Event Flags.pdf

    uCOS-II和Event Flags.pdf

    Event Flags及其使用

    Event Flags及其使用 更多资源请访问http://www.59186618.com

    C++标准库(第二版)英文版.pdf

    The C++ Standard Library A Tutorial and Reference (2nd Edition)+cppstdlib-code.zip C++标准库(第二版)英文版.pdf 非扫描版+源代码 Prefaceto the SecondEdition xxiii Acknowledgments for the Second...

    print_flags.rar_MaskEd

    Print string that matches bit masked flags for Linux.

    v8-flags, 在运行时,配置v8标志.zip

    v8-flags, 在运行时,配置v8标志 v8-flags 运行时配置v8标志。// use-strict-violator.jsa = "I'm the trouble starter, punking instigator"module.export

    py-flags:Python 3的类型安全(位)标志

    这些非常类似于此flags.Flags类。 只需阅读简短的“和“部分就可以开始使用该模块。 剩下的就是细节。 内容 别名 遗产 使用函数调用语法进行子类化 支持的运营 实例方法和属性 类方法 @unique和@unique_bits装饰...

Global site tag (gtag.js) - Google Analytics