zoj 2771 - Get Out of the Glass

题目:有三层玻璃叠在一起,一束斜着照射的光纤从最上面射入,问有多少条光线反射n次。

分析:dp,分成奇偶两种状况考虑;

奇数情况:每个面的光线等于上次的本平面以上的点的反射;

偶数情况:每个面的光线等于上次的本平面一下的点的反射。

说明:(2011-09-19 01:29)。

#include <stdio.h>
#include <string.h>

long long F[ 61 ][ 4 ];

int main()
{
    int i,j,k,n;
    memset( F, 0L, sizeof( F ) );
    F[ 0 ][ 0 ] = 1L;

    for ( i = 1 ; i <= 60 ; ++ i )
    for ( j = 0 ; j <= 3  ; ++ j )
        if ( i%2 ) {
            for ( k =  0  ; k < j ; ++ k )
                F[ i ][ j ] += F[ i-1 ][ k ];
        }else {
            for ( k = j+1 ; k <= 3 ; ++ k )
                F[ i ][ j ] += F[ i-1 ][ k ];
        }
    while ( scanf("%d",&n) != EOF ) {
        long long sum = 0;
        for ( i = 0 ; i < 3 ; ++ i )
            sum += F[ n ][ i+n%2 ];
        printf("%lld\n",sum);
    }
    return 0;
}
时间: 2024-10-25 08:09:35

zoj 2771 - Get Out of the Glass的相关文章

ZOJ 2771

  Description Considering a light entering three adjacent planes of glass. At any meeting surface, the light may either reflect or continue straight through. For example, here is the light bouncing five times before it leaves the glass. Given the tim

zoj 2006 Glass Beads

Glass Beadshttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1006 Time Limit: 2 Seconds      Memory Limit: 65536 KB Once upon a time there was a famous actress. As you may expect, she played mostly Antique Comedies most of all. All the peopl

图论 500题——主要为hdu/poj/zoj

转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并查集======================================[HDU]1213   How Many Tables   基础并查集★1272   小希的迷宫   基础并查集★1325&&poj1308  Is It A Tree?   基础并查集★1856   More i

概率dp ZOJ 3640

Help Me Escape Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3640 Appoint description:  System Crawler  (2014-10-22) Description Background     If thou doest well, shalt thou not be accepted? an

zoj 2156 - Charlie&#39;s Change

题目:钱数拼凑,面值为1,5,10,25,求组成n面值的最大钱币数. 分析:dp,01背包.需要进行二进制拆分,否则TLE,利用数组记录每种硬币的个数,方便更新. 写了一个 多重背包的 O(NV)反而没有拆分快.囧,最后利用了状态压缩优化 90ms: 把 1 cents 的最后处理,其他都除以5,状态就少了5倍了. 说明:貌似我的比大黄的快.(2011-09-26 12:49). #include <stdio.h> #include <stdlib.h> #include <

ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 最小生成树 Kruskal算法

题目链接:ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 Building a Space Station Time Limit: 2 Seconds      Memory Limit: 65536 KB You are a member of the space station engineering team, and are assigned a task in the construction process of the statio

ZOJ 3607 Lazier Salesgirl (贪心)

Lazier Salesgirl Time Limit: 2 Seconds      Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling. She can sell the i-th customer a piece of bread for price pi. But she is so lazy

ZOJ - 2243 - Binary Search Heap Construction

先上题目: Binary Search Heap Construction Time Limit: 5 Seconds      Memory Limit: 32768 KB Read the statement of problem G for the definitions concerning trees. In the following we define the basic terminology of heaps. A heap is a tree whose internal n

ZOJ 2859 二维线段树

思路:自己写的第二发二维线段树1A,哈哈,看来对二维的push操作比较了解了:但是还没遇到在两个线段树中同时进行push操作的,其实这题我是想在x维和y维同时进行push操作的,但是想了好久不会,然后看到这题又给出10秒,然后想想在x维线段直接单点查询肯定也过了,然后在第二维就只有pushup操作,在第一维线段树没有pushup操作.要是在第一维也有pushup操作的话,那就不用单点查询那么慢了.不过也A了,想找题即在二维同时进行pushup和pushdown操作的. #include<iost