zoukankan      html  css  js  c++  java
  • uva 580 危险的组合(排列组合)


    Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

     Status

    Description

    Download as PDF
     

    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 ofn 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
    30 0

    Sample Output 

    3
    8
    974791728

    题解:

    有U和L两种盒子,数量足够多,要把n个盒子排成一行,但至少要有3个U放在一起,问有多少种方法.

    可以逆向考虑,两种情况。

     (1)前面n-1个盒子已经能符合要求,则第n个盒子无论是U还是L,都满足情况。

    (2)前面n-1个盒子不能符合要求,即只有最后4个满足情况LUUU并且前面并没有连续的三个U的情况才能满足情况
    #include<iostream>
    using namespace std;
    long long dp[40];
    int main()
    {
        dp[0]=dp[1]=dp[2]=0;
        dp[3]=1;
        for(int i=4;i<=30;i++)
        dp[i]=2*dp[i-1]+(1<<(i-4))-dp[i-4];
        int n;
        while(cin>>&&n) cout<<dp[n]<<endl;
        return 0;
    }
  • 相关阅读:
    Ceph纠删码编码机制
    Vmware error:无法获得 VMCI 驱动程序的版本: 句柄无效。
    Virtual Box 安装过程(卸载Vmware后)
    解决安卓SDK更新dl-ssl.google.com无法连接的方法
    《中文核心期刊要目总览(2014年版)》——计算机、自动化类
    2014中国科技核心期刊(中国科技论文统计源期刊)名录——计算机类
    计算机专业方面的期刊
    Office 中的各种小tips(更新中)
    博客园添加背景音乐
    jmeter定时器
  • 原文地址:https://www.cnblogs.com/hfc-xx/p/4746079.html
Copyright © 2011-2022 走看看