soj1049.Mondriaan
1049. Mondriaan
Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
Description
Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One day, while working on his latest project, he was intrigued by the number of different ways in which he could order several objects to fill an arbitrary region. Expert as he was in this material, he saw at a glance that this was going to be too hard, for there seemed to be innumerable ways to do this. To make his task a little easier, he decided to start with only two kinds of objects: squares with width 1 and height 1, and rectangles with width 2 and height 1. After working on it for half an hour, he knew that even this was too much, for all of his paper was filled with pages like this. The only paper left was his toilet paper, and strange as it now seems, he continued with his task. Fortunately the width of the toilet paper equaled the width of the rectangle, which simplified things a lot. This seemed to do just fine, for in a few minutes time, he produced the following drawing:
Mondriaan decided to make several of these drawings, each on a piece of toilet paper with a different length. He wanted to give the drawings in his ‘toilet series’ names according to the last digit of the number of ways to fill a piece of toilet paper of a particular length with squares and rectangles. Computers might come in handy in cases like this, so your task is to calculate the name of the drawing, given the length of the toilet paper. The length will be measured in the same dimension as the squares and rectangles.
Input
The input consists of a line containing the number N (1≤N≤100) of drawings in the series. Each consecutive line consists of a number L (0≤L≤1000000) which is the length of the piece of toilet paper used for the drawing.
Output
The output consists of the number that is the name for the corresponding drawing.
Sample Input
5
0
1
2
3
4
Sample Output
1
2
7
2
1
这道题与hdu1992.Tiling a Grid With Dominoes非常类似。也是铺地板的动态规划问题。
注意分析:
1.铺满2*1时,
共有两种情况
2.铺满2*2时,且不和上面情况重复的有3种,
共有3种情况
3.当i >= 3 时,我们又不想与上面的情况重复,那么只有选择突出一个的情况,也就是永远只能靠小正方形来填满的情况:
共有2种情况
因此得到通项:dp[i] = 2*dp[i-1] + 3*dp[i-2] + 2*(dp[i-3]+dp[i-4]+dp[i-5]+......+dp[1] + dp[0])
然后再类比dp[i-1]的式子,消参即可得到简化式子。
#include <iostream>
#include <memory.h>
using namespace std; int dp[1000002];
int main()
{
int i;
dp[0] = 1;
dp[1] = 2;
dp[2] = 7;
for(i = 3;i <= 1000000;i++)
{
dp[i] = (3*dp[i-1] + dp[i-2] - dp[i-3] + 10) % 10; //这里值得注意
}
int N;
cin >> N;
while(N--)
{
int a;
cin >> a;
cout << dp[a] << endl;
}
return 0;
}
soj1049.Mondriaan的更多相关文章
- [poj2411] Mondriaan's Dream (状压DP)
状压DP Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One nigh ...
- POJ 题目2411 Mondriaan's Dream(状压DP)
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 13519 Accepted: 787 ...
- POJ 2411 Mondriaan's Dream
状压DP Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 9938 Accepted: 575 ...
- POJ2411 Mondriaan's Dream
Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, af ...
- 状压DP POJ 2411 Mondriaan'sDream
题目传送门 /* 题意:一个h*w的矩阵(1<=h,w<=11),只能放1*2的模块,问完全覆盖的不同放发有多少种? 状态压缩DP第一道:dp[i][j] 代表第i行的j状态下的种数(状态 ...
- HDU 1400 (POJ 2411 ZOJ 1100)Mondriaan's Dream(DP + 状态压缩)
Mondriaan's Dream Problem Description Squares and rectangles fascinated the famous Dutch painter Pie ...
- poj 2411 Mondriaan's Dream(状态压缩dp)
Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, af ...
- poj 2411 Mondriaan's Dream 【dp】
题目:id=2411" target="_blank">poj 2411 Mondriaan's Dream 题意:给出一个n*m的矩阵,让你用1*2的矩阵铺满,然 ...
- POJ2411 Mondriaan's Dream(状态压缩)
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 15295 Accepted: 882 ...
随机推荐
- Maven解读:强大的依赖体系
Github地址:https://github.com/zwjlpeng/Maven_Detail Maven最大的好处就是能够很方便的管理项目对第三方Jar包的依赖,只需在Pom文件中添加几行配置文 ...
- scrapy-yield scrapy.Request()不执行、失效、Filtered offsite request to错误 [转]
scrapy错误:yield scrapy.Request()不执行.失效.Filtered offsite request to错误.首先我们在Request()方法里面添加这么一个东东: yiel ...
- windows多线程(十) 生产者与消费者问题
一.概述 生产者消费者问题是一个著名的线程同步问题,该问题描述如下:有一个生产者在生产产品,这些产品将提供给若干个消费者去消费,为了使生产者和消费者能并发执行,在两者之间设置一个具有多个缓冲区的缓冲池 ...
- autoboxing and unboxing
Why does 128==128 return false but 127==127 return true public static void autoboxingUnboxing(){ Int ...
- GraphQL & REST API
GraphQL & REST API GraphQL https://mp.weixin.qq.com/s/X-jm7jLXWmMmLBVgHfkRiQ https://webapplog.c ...
- 字符串(string)与整型(int)、浮点型(float)等之间的转换
#include <stdlib.h> 1.int/float to string/array: C语言提供了几个标准库函数,可以将任意类型(整型.长整型.浮点型等)的数字转换为字符串,下 ...
- zabbix短信(阿里云短信平台)与邮件报警
环境说明 操作系统 centos7 zabbix_server zabbix 4.0.3 python 3.6.5 短信平台 阿里云短信 zabbix_server配置信息 1 [root@cp-hb ...
- [AT2384] [agc015_f] Kenus the Ancient Greek
题目链接 AtCoder:https://agc015.contest.atcoder.jp/tasks/agc015_f 洛谷:https://www.luogu.org/problemnew/sh ...
- 【BZOJ1034】泡泡堂(贪心)
[BZOJ1034]泡泡堂(贪心) 题面 BZOJ 洛谷 题解 很基础的贪心,然而我竟然没写对...身败名裂. 大概就是类似田忌赛马. 先拿看当前最大值是否能否解决对面最大值,否则检查能否用最小值来兑 ...
- 【BZOJ1858】序列操作(线段树)
[BZOJ1858]序列操作(线段树) 题面 BZOJ 题解 这题思路很简单,细节很烦,很码 维护区间翻转和区间赋值标记 当打到区间赋值标记时直接覆盖掉翻转标记 下放标记的时候先放赋值标记再放翻转标记 ...