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 ...
随机推荐
- 搭建zabbix详细步骤
关闭selinux和防火墙 selinux关闭: 1 命令查看出selinux的状态sestatus -v2 临时关闭 selinuxsetenforce 03 永久关闭selinuxvi /etc/ ...
- Sprint2的每日更新
按照以下过程进行 ProductBacklog:继续向下细化 Sprint 计划会议:确定此次冲刺要完成的目标 Sprint Backlog:新的冲刺要完成的内容 任务认领 Sprint周期 看板:一 ...
- sql update set from 的用法 (转)
关键字: update set from 下面是这样一个例子: 两个表a.b,想使b中的memo字段值等于a表中对应id的name值 表a:id, name 1 ...
- Robot Framework 教程 (7) - 使用For循环
在自动化测试过程中,使用For循环来对某个动作进行重复操作是很普遍的行为.在Robot Framework中,各种测试库中均提供了多种方式的For循环结构,在其中覆盖了大部分类型的循环类型.而Robo ...
- windows 下查看进程开始运行的时间
1. 打开运行 输入 msinfo32 然后在软件环境- 正在运行任务- 就能够看到运行开始的时间了.
- js & click copy to clipboard
js & click copy to clipboard https://www.cnblogs.com/xgqfrms/p/9999061.html https://www.cnblogs. ...
- java static{}块
java中static{}块只有在类加载是才会被调用. 这说明:static只有可能被调用一次. 原因:首先理解什么是类加载,区分类加载和申明对象的区别. public class StaticTes ...
- MySQL-常见数据拆分办法
在生产环境中,由于业务的增长或者业务的拆分,DBA经常需要拆库操作.那么我们常见的拆库手段有哪些呢? 我这里提供几种解决办法: 1. 使用mysqldump 把表逻辑倒出,然后再source 到其它地 ...
- LAMP 环境下添加多个虚拟主机(网站)
Ubuntu系统 #在/var/www目录下新建两个文件夹bbs和oa,执行完以上命令后,/var/www目录下有bbs.oa三个文件夹,名称与二级域名对应,分别存放三个系统的php文件,这样便于日后 ...
- P4611 [COCI2011-2012#7] TRAMPOLIN
题目背景 有很多超级英雄:蝙蝠侠,蜘蛛侠,超人等.其中,有一位叫牛.今天他想模仿蜘蛛侠,所以他选择了一排高大的摩天楼来跳. 题目描述 具体而言,他选择了一个由 N 个摩天大楼构成的序 列,从左到右编号 ...