XJOI 3266 Dyeing 染色 题解

本文介绍了XJOI 3266染色问题,该问题要求在一行中用三种颜色染色,相邻颜色不同且首尾颜色不同。给出了暴力解法的局限性,并详细解释了利用递推公式f(n)=f(n-1)+2*f(n-2)(n>3)解决此问题的方法,适合信息学竞赛参与者学习。
摘要由CSDN通过智能技术生成

英文

Time Limit:1s Memory Limit:256M

Description

N grid in a line.Using three colour(red,pink and green) to dye the grid,each grid dyeing one colour,the rule is every two adjacent grid should be different colour,and the first grid and the last grid in the line should be different colour.Please calculate the ways you dye.

Input

One integer n 1<=n<=50

Output

One integer.

Sample Input

2

Sample Output

6

中文

时间:1s 空间:256M

题目描述:

有排成一行的n个方格,用红(Red)、粉(Pink)、绿(Green)三色涂每个格子,每格涂一色,要求任何相邻的方格不能同色,且首尾两格也不同色.求全部的满足要求的涂法.

输入格式:

输入一个整数n

输出格式:

输出一个整数

样例输入:

2

样例输出:

6

约定:

0<=n<=50

提示:

看到这题后,是不是准备先来个暴力?没错,暴力已经准备好了:

#include <iostream>
#include <cstdio>
#include <string>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值