HDU - 2018 :递推

http://acm.hdu.edu.cn/showproblem.php?pid=2018

#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <assert.h>
#include <set>
#include <cmath>
#include <queue>
#include <cstdlib>
#include <iostream>
#include <bitset>
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
const int mxn = 1e2+5;
int n,m,k,t,dp[mxn],a[mxn];
int main()
{
    for(int i=1;i<55;i++)
        dp[i] = i<=4 ? i : dp[i-1]+dp[i-3] ;
    while(cin>>n)
    {
        if(n) cout<<dp[n]<<endl;
        else break;
    }
    return 0 ;
}

原文地址:https://www.cnblogs.com/Shallow-dream/p/12248490.html

时间: 2024-08-01 00:40:33

HDU - 2018 :递推的相关文章

hdu 1267 递推

下沙的沙子有几粒? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4326    Accepted Submission(s): 2268 Problem Description 2005年11月份,我们学校参加了ACM/ICPC 亚洲赛区成都站的比赛,在这里,我们获得了历史性的突破,尽管只是一枚铜牌,但获奖那一刻的激动,也许将永远铭刻

hdu 2044-2050 递推专题

总结一下做递推题的经验,一般都开成long long (别看项数少,随便就超了) 一般从第 i 项开始推其与前面项的关系(动态规划也是这样),而不是从第i 项推其与后面的项的关系. hdu2044:http://acm.hdu.edu.cn/showproblem.php?pid=2044 //没开成long long WA了一次 #include<iostream> #include<cstdio> #include<algorithm> #include <s

hdu 2604 递推 矩阵快速幂

HDU 2604 Queuing (递推+矩阵快速幂) 这位作者讲的不错,可以看看他的 #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstring> using namespace std; const int N = 5; int msize, Mod; struct Mat { int mat[N][N]; }; M

HDU 2842 (递推+矩阵快速幂)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2842 题目大意:棒子上套环.第i个环能拿下的条件是:第i-1个环在棒子上,前i-2个环不在棒子上.每个环可以取下或放上,cost=1.求最小cost.MOD 200907. 解题思路: 递推公式 题目意思非常无聊,感觉是YY的. 设$dp[i]$为取第i个环时的总cost. $dp[1]=1$,$dp[2]=2$,前两个环取下是没有条件要求的. 从i=3开始,由于条件对最后的环限制最大,所以从最后一

hdu 1297 递推难题

这题的话,我能玩一年 今天做了很多递推的题,这题无疑是最复杂的 其实可以看出来,2,3,4,5为一类,不妨定义为2型,1,6为一类,定义为1型 规定num[i]为结尾是i的凹槽的数量 我们可以能轻易的推出 sum = num[1]*2+num[2]*4 现在我们开始分析这个递推式的构成 根据第n个凹槽前 能不能构成一把lock,我们将情况分为两类 A:能构成lock 1.如果当前结尾为1类,我们用‘1’分析好了(下面也是用1),n-1的结尾必然不能是‘6’,因为1和6不能直接相连,根据题意就知道

HDU 3123-GCC(递推)

GCC Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 3993    Accepted Submission(s): 1304 Problem Description The GNU Compiler Collection (usually shortened to GCC) is a compiler system produc

hdu 5459 递推

中等递推题: ans[i] = ans[i - 2] + ans[i - 1] + ( sum[i - 2] + cnt[i - 2] * len[i - 1] ) * cnt[i - 1] - sum[i - 1] * cnt[i - 2]; 其中,ans[i]代表答案,cnt[i]代表ith个message中有多少个cff,sum[i]代表ith个message中cff的c的位置的和(从右向左index依次为1,2...),len[i]代表ith个message的长度. 1 #include

HDU 4465 递推与double的精确性

题目大意不多说了 这里用dp[i][0] 代表取完第一个盒子后第二个盒子剩 i 个的概率,对应期望就是dp[i][0] *i dp[i][1] 就代表取完第二个盒子后第一个盒子剩 i 个的概率 dp[i][0]  =  p^(n+1) * (1-p)^(n-i) * C(2*n-i , n-i) = p^(n+1) * (1-p)^(n-i) * (2*n-i)! / (n-i)! / n! dp[i+1][0]  = p^(n+1) * (1-p)^(n-i-1) * C(2*n-i-1 ,

hdu 2563 递推

#include <stdio.h> #include <string> #include <iostream> #include <string.h> #include <map> #define MAX 30 using namespace std; /* 一道很好的递推题,虽然思路是从discuss中获得,但是应该想简单些,从前一次走可获得, 每次向上走可以为下一次获得3步机会,而向左或者向右则只能由两种. */ int main() {

hdu 1297 递推

递推式参考:http://www.2cto.com/kf/201302/190324.html 数据较大,需要用大整数来写. 1 import java.math.*; 2 import java.util.Scanner; 3 4 public class Main 5 { 6 public static void main( String[] args ) 7 { 8 Scanner cin = new Scanner(System.in); 9 BigInteger[] f = new B