题意:n位长的01序列(0 < n < 45),但不能出现连续的两个1,问序列有多少种。

题目链接:

id=1953" target="_blank">http://poj.org/problem?

id=1953

——>>设dp[i][j]表示前 i 位中第 i 位为 j 时的序列数。则状态转移方程为:

dp[i][0] = dp[i - 1][0] + dp[i - 1][1];

dp[i][1] = dp[i - 1][0];

由于对于同样的n,其结果是固定的,所以能够对一个n仅仅计算一次,然后记住她。。

#include <cstdio>
#include <cstring> const int MAXN = 45 + 1; int n;
int dp[MAXN][2]; void Init()
{
memset(dp, -1, sizeof(dp));
} void Dp(int i)
{
if (i == 1)
{
dp[i][0] = dp[i][1] = 1;
return;
} if (dp[i][0] != -1)
{
return;
} Dp(i - 1);
dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
dp[i][1] = dp[i - 1][0];
} int main()
{
int T, nCase = 0; scanf("%d", &T);
while (T--)
{
scanf("%d", &n);
Init();
Dp(n);
printf("Scenario #%d:\n", ++nCase);
printf("%d\n\n", dp[n][0] + dp[n][1]);
} return 0;
}

poj - 1953 - World Cup Noise(dp)的更多相关文章

  1. POJ 1953 World Cup Noise(递推)

    https://vjudge.net/problem/POJ-1953 题意:输入一个n,这n位数只由0和1组成,并且不能两个1相邻.计算共有多少种排列方法. 思路:递推题. 首先a[1]=2,a[2 ...

  2. poj 1953 World Cup Noise (dp)

    World Cup Noise Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16774   Accepted: 8243 ...

  3. POJ 1953 World Cup Noise

    World Cup Noise Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 14397   Accepted: 7129 ...

  4. Poj 1953 World Cup Noise之解题报告

    World Cup Noise Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16369   Accepted: 8095 ...

  5. POJ 2168 Joke with Turtles(DP)

    Description There is a famous joke-riddle for children: Three turtles are crawling along a road. One ...

  6. POJ 1485:Fast Food(dp)&& 面试题

    题目链接 题意 给出 n 个餐厅,m 个停车场,现在要将 n 个餐厅中的 m 个变成停车场,使得每个餐厅到最近的停车场的距离之和最短,输出哪个餐厅变成停车场和它服务哪些餐厅,还有最短距离之和. 思路 ...

  7. poj - 1050 - To the Max(dp)

    题意:一个N * N的矩阵,求子矩阵的最大和(N <= 100, -127 <= 矩阵元素 <= 127). 题目链接:http://poj.org/problem?id=1050 ...

  8. POJ 2533——Longest Ordered Subsequence(DP)

    链接:http://poj.org/problem?id=2533 题解 #include<iostream> using namespace std; ]; //存放数列 ]; //b[ ...

  9. POJ 3666 Making the Grade (DP)

    题意:输入N, 然后输入N个数,求最小的改动这些数使之成非严格递增即可,要是非严格递减,反过来再求一下就可以了. 析:并不会做,知道是DP,但就是不会,菜....d[i][j]表示前 i 个数中,最大 ...

随机推荐

  1. strust2的核心和工作原理

    在学习strust2之前,我们要明白使用struts2的目的是什么?它能给我们带来什么样的好处? 设计目标 Strust设计的第一目标就是使MVC模式应用于web程序设计. 技术优势 Struts2有 ...

  2. storm性能优化

    Storm 性能优化 目录 场景假设 调优步骤和方法 Storm 的部分特性 Storm 并行度 Storm 消息机制 Storm UI 解析 性能优化 场景假设 在介绍 Storm 的性能调优方法之 ...

  3. opensue fstab故障恢复

    date: 20140505 author: Jin 故障背景: 早上启动本本 无法启动,报错信息(几个关键) WARNING:Failed to connect to lvmetad: No suc ...

  4. Android Content Provider Security(转)

    四大组件之一-content provider安全详解 原帖地址:http://drops.wooyun.org/tips/4314 0x00 科普 内容提供器用来存放和获取数据并使这些数据可以被所有 ...

  5. NServiceBus入门:启程(Introduction to NServiceBus: Getting started)

    原文地址:https://docs.particular.net/tutorials/intro-to-nservicebus/1-getting-started/ 侵删. 最好的学习NService ...

  6. Linux PHP 编译参数详解(一)

    Fast-CGI: ./configure --prefix=/usr/local/php --enable-fastcgi --enable-force-cgi-redirect --with-co ...

  7. ocx控件打印之基础篇

      Visual C++6.0是开发Windows应用程序的强大工具,但是要通过它实现程序的打印功能,一直是初学者的一个难点,经常有朋友询问如何在VC中实现打印功能,他们往往感到在MFC提供的框架内实 ...

  8. git 统计代码量 shell脚本

    #!/bin/bash # 统计代码量 # 使用方法: sh gitstat.sh "2017-11-01" "2017-11-30" "JamKon ...

  9. NormalMap 贴图 【转】

    转载: http://www.zwqxin.com/archives/shaderglsl/review-normal-map-bump-map.html   说起Normal Map(法线贴图),就 ...

  10. 解决安装mysqlclient出现问题:mysql_config: not found

    解决安装mysqlclient出现如下问题: Complete output from command python setup.py egg_info: /bin/sh: : mysql_confi ...