zoukankan      html  css  js  c++  java
  • URAL 1260 Nudnik Photographer(递推)

    题目链接

    题意 : 给你1到n这n个数,排成一排,然后1放在左边最开始,剩下的数进行排列,要求排列出来的数列必须满足任何两个相邻的数之间的差不能超过2,问你有多少种排列

    思路 : 对于dp[n], n个人时求F[n]。第2个位置放2时有F[n-1]种;第2个位置放3,第3个位置放2,第4个位置只能放4,有F[n-3]种;第2个位置放3,第3个位置放5,13578642,有1种;第2个位置放3,第3个位置不能放4。      

    所以:

    1、12……(dp[n-1])

    2、1324……(dp[n-3])

    3、1357……8642(一种确定的情况)

     1 //URAL 1260
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <iostream>
     5 
     6 using namespace std ;
     7 int dp[57] ;
     8 
     9 void chart()
    10 {
    11     dp[1] = dp[2] = 1 ;
    12     dp[3] = 2 ;
    13     for(int i = 4 ; i <= 56 ; i++)
    14         dp[i] = dp[i-1]+dp[i-3]+1 ;
    15 }
    16 int main()
    17 {
    18     int n ;
    19     chart() ;
    20     while(~scanf("%d",&n))
    21     {
    22         printf("%d
    ",dp[n]) ;
    23     }
    24     return 0 ;
    25 }
    View Code
  • 相关阅读:
    [SDOI2015]约数个数和
    [POI2007]ZAP-Queries
    fpu栈溢出
    shader 汇编
    sample a texture as a rendertarget
    ID3d11asynchronous
    DEVICE DRAW VERTEX BUFFER TOO SMALL
    模型的一个点显示在原点
    setrendertraget 上下颠倒
    skinned mesh 蜘蛛样
  • 原文地址:https://www.cnblogs.com/luyingfeng/p/3663605.html
Copyright © 2011-2022 走看看