集训第六周 M题
Description
During the early stages of the Manhattan Project, the dangers of the new radioctive materials were not widely known. Vast new factory cities were built to manufacture uranium and plu- tonium in bulk. Compounds and solutions of these substances were accumulating in metal barrels, glass bottles and cardboard box piles on the cement floors of store rooms. Workers did not know that the substances they were handling could result in sickness, or worse, an explosion. The officials who new the danger assumed that they could ensure safety by never assembling any amount close to the critical mass estimated by the physicists. But mistakes were made. The workers, ignorant of the the dangers, often did not track these materials care- fully, and in some cases, too much material was stored together - an accident was waiting to happen.
Fortunately, the dangers were taken seriously by a few knowledgeable physicists. They drew up guidelines for how to store the materials to eliminate the danger of critical mass accumulations. The system for handling uranium was simple. Each uranium cube was marked ``U''. It was to be stacked with lead cubes (marked ``L'') interspersed. No more than two uranium cubes could be next to each other on a stack. With this simple system, a potential for the uranium reaching critical mass (three stacked next to each other) was avoided. The second constraint is that no more than thirty cubes can be stacked on top of each other, since the height of the storage room can only accommodate that many.
One of the physicists was still not completely satisfied with this solution. He felt that a worker, not paying attention or not trained with the new system, could easily cause a chain reaction. He posed the question: consider a worker stacking the radioactive cubes and non radioactive cubes at random on top of each other to a height of n cubes; how many possible combinations are there for a disaster to happen?
For example, say the stack is of size 3. There is one way for the stack to reach critical mass - if all three cubes are radioactive.
1: UUU
However, if the size of the stack is 4, then there are three ways:
1: UUUL
2: LUUU
3: UUUU
Input
The input is a list of integers on separate lines. Each integer corresponds to the size of the stack and is always greater than 0. The input is terminated with a integer value of 0.
Output
For each stack, compute the total number of dangerous combinations where each cube position in the linear stack can either be `` L'' for lead, or `` U'' for uranium. Output your answer as a single integer on a line by itself.
Sample Input
4
5
0
Sample Output
3
8
首先可以知道危险的情况根据物体数而有所不同,使用dp递推的话可以有初始化如下
dp[0]=dp[1]=dp[2]=0;dp[3]=1;dp[4]=3
dp式为:
dp[i]=2*dp[i-1]+(1<<(i-4))-dp[i-4]
#include"cstdio"
long long dp[];
int main()
{
dp[]=dp[]=dp[]=;
dp[]=;
dp[]=;
for(int i=;i<=;i++)
dp[i]=*dp[i-]+(<<(i-))-dp[i-];
int n;
while(~scanf("%d",&n)&&n) printf("%d\n",dp[n]);
return ;
}
集训第六周 M题的更多相关文章
- 集训第六周 O题
Description Gerald got a very curious hexagon for his birthday. The boy found out that all the angle ...
- 集训第六周 E题
E - 期望(经典问题) Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit S ...
- 程序设计入门—Java语言 第六周编程题 1 单词长度(4分)
第六周编程题 依照学术诚信条款,我保证此作业是本人独立完成的. 1 单词长度(4分) 题目内容: 你的程序要读入一行文本,其中以空格分隔为若干个单词,以'.'结束.你要输出这行文本中每个单词的长度.这 ...
- hdu 4548 第六周H题(美素数)
第六周H题 - 数论,晒素数 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u De ...
- 集训第六周 古典概型 期望 D题 Discovering Gold 期望
Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell o ...
- 集训第六周 矩阵快速幂 K题
Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. F ...
- 集训第六周 数学概念与方法 计数 排列 L题
Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样. 话 ...
- 集训第六周 数学概念与方法 J题 数论,质因数分解
Description Tomorrow is contest day, Are you all ready? We have been training for 45 days, and all g ...
- 集训第六周 数学概念与方法 数论 线性方程 I题
Description The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the Tr ...
随机推荐
- mysql 循环批量插入
背景 前几天在MySql上做分页时,看到有博文说使用 limit 0,10 方式分页会有丢数据问题,有人又说不会,于是想自己测试一下.测试时没有数据,便安装了一个MySql,建了张表,在建了个whil ...
- _bzoj1059 [ZJOI2007]矩阵游戏【二分图匹配】
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1059 保存匈牙利模板. #include <cstdio> #include & ...
- AC自动机 HDOJ 2222 Keywords Search
题目链接 题意:每个文本串的出现次数 分析:入门题,注意重复的关键字算不同的关键字,还有之前加过的清零. 新模板,加上last跑快一倍 #include <bits/stdc++.h> ...
- 436 Find Right Interval 寻找右区间
给定一组区间,对于每一个区间 i,检查是否存在一个区间 j,它的起始点大于或等于区间 i 的终点,这可以称为 j 在 i 的“右侧”.对于任何区间,你需要存储的满足条件的区间 j 的最小索引,这意味着 ...
- 调用wsdl接口,参数是xml格式
1.最近太累了,好困.闲话少许直奔主题吧.上代码 try{ String wsurl = "http://172.16.16.236:9999/xxx/ws/WSService?wsdl&q ...
- AJPFX:学习JAVA程序员两个必会的冒泡和选择排序
* 数组排序(冒泡排序)* * 冒泡排序: 相邻元素两两比较,大的往后放,第一次完毕,最大值出现在了最大索引处* * 选择排序 : 从0索引开始,依次和后面元素比较,小的往前放,第一次完毕,最小值出现 ...
- Docker安装jenkins(六)
这里是在linux环境下安装docker之后,在doucer内安装jenkins --------------------docker 安装 jenkins---------------------- ...
- [BZOJ1005][HNOI2008]明明的烦恼 数学+prufer序列+高精度
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int N; ...
- MySQL多表
一.外键 1.外键:链接两张表的字段,通过主表的主键和从表的外键来描述主外键关系,呈现的是一对多的关系.例如:商品类别(一)对商品(多),主表:商品类别表,从表:商品表. 2.外键的特点:从表外键的值 ...
- OpenGl之旅-—初识opengl
昨天学习了如何使用codeblocks来编译运行一个opengl的项目.在创建一个新的opengl项目时他默认已经写了一个示例,今天我们就上面的例子进行下代码的剖析,以此来敲开opengl的神秘大门. ...