递推DP URAL 1260 Nudnik Photographer

题目传送门

 1 /*
 2     递推DP: dp[i] 表示放i的方案数,最后累加前n-2的数字的方案数
 3 */
 4 #include <cstdio>
 5 #include <algorithm>
 6 #include <cmath>
 7 #include <cstring>
 8 using namespace std;
 9
10 const int MAXN = 1e4 + 10;
11 const int INF = 0x3f3f3f3f;
12 int dp[60];
13
14 int main(void)        //URAL 1260 Nudnik Photographer
15 {
16     //freopen ("G.in", "r", stdin);
17
18     int n;
19     while (scanf ("%d", &n) == 1)
20     {
21         memset (dp, 0, sizeof (dp));
22         dp[1] = 1;
23         for (int i=2; i<=n; ++i)
24         {
25             dp[i] = dp[i-1];
26             if (i > 3)
27             {
28                 dp[i] += dp[i-3];
29             }
30         }
31
32         long long ans = dp[n];
33         if (n > 2)
34         {
35             for (int i=1; i<=n-2; ++i)    ans += dp[i];
36         }
37         printf ("%I64d\n", ans);
38     }
39
40     return 0;
41 }
时间: 2024-08-09 20:37:42

递推DP URAL 1260 Nudnik Photographer的相关文章

递推DP URAL 1353 Milliard Vasya&#39;s Function

题目传送门 1 /* 2 题意:1~1e9的数字里,各个位数数字相加和为s的个数 3 递推DP:dp[i][j] 表示i位数字,当前数字和为j的个数 4 状态转移方程:dp[i][j] += dp[i-1][j-k],为了不出现负数 5 改为:dp[i][j+k] += dp[i-1][j] 6 */ 7 #include <cstdio> 8 #include <cstring> 9 #include <cmath> 10 #include <algorithm

ural 1260. Nudnik Photographer 规律dp

点击打开链接 1260. Nudnik Photographer Time limit: 1.0 second Memory limit: 64 MB If two people were born one after another with one second difference and one of them is a child, then the other one is a child too. We get by induction that all the people ar

递推DP URAL 1031 Railway Tickets

题目传送门 1 /* 2 简单递推DP:读题烦!在区间内的都更新一遍,dp[]初始化INF 3 注意:s1与s2大小不一定,坑! 4 详细解释:http://blog.csdn.net/kk303/article/details/6847948 5 */ 6 #include <cstdio> 7 #include <iostream> 8 #include <algorithm> 9 #include <cstring> 10 #include <s

递推DP URAL 1119 Metro

题目传送门 1 /* 2 题意:已知起点(1,1),终点(n,m):从一个点水平或垂直走到相邻的点距离+1,还有k个抄近道的对角线+sqrt (2.0): 3 递推DP:仿照JayYe,处理的很巧妙,学习:) 4 好像还要滚动数组,不会,以后再补 5 */ 6 #include <cstdio> 7 #include <iostream> 8 #include <algorithm> 9 #include <cmath> 10 #include <cs

递推DP URAL 1017 Staircases

题目传送门 1 /* 2 题意:给n块砖头,问能组成多少个楼梯,楼梯至少两层,且每层至少一块砖头,层与层之间数目不能相等! 3 递推DP:dp[i][j] 表示总共i块砖头,最后一列的砖头数是j块的方案数 4 状态转移方程:dp[i][j] += dp[i-j][k] 表示最后一列是j,那么上一个状态是少了最后一列 5 总共i-j块砖头,倒数第二列是k块砖头.k<j, j<=i 6 最后累加dp[n][i], i<n因为最少要两层 7 dp[0][0] = 1; 8 还有更简单的做法,没

URAL 1260 Nudnik Photographer DFS DP

题目:click here :这个题可以先dfs深搜下,规律dp dfs: 1 #include <bits/stdc++.h> 2 using namespace std; 3 #define S second 4 typedef long long ll; 5 const int INF = 0x3f3f3f3f; 6 const int M = 1e5+3; 7 8 int s; 9 int cnt = 0; 10 bool vis[60]; 11 void dfs( int last,

递推DP URAL 1081 Binary Lexicographic Sequence

题目传送门 1 /* 2 dp[i][1]/dp[i][0] 表示从左往右前i个,当前第i个放1或0的方案数 3 k -= dp[n][0] 表示当前放0的方案数不够了,所以必须放1,那么dp[n][0]个方案数都不能用了 4 相当于k减去这么多 5 详细解释:http://www.cnblogs.com/scau20110726/archive/2013/02/05/2892587.html 6 */ 7 #include <cstdio> 8 #include <algorithm&

递推DP URAL 1167 Bicolored Horses

题目传送门 1 /* 2 题意:k个马棚,n条马,黑马1, 白马0,每个马棚unhappy指数:黑马数*白马数,问最小的unhappy指数是多少 3 状态转移方程:dp[i][l] = min (dp[i][l], dp[i-1][j] + cur * (l - j - cur)) 表示第l匹马要不还在i马棚,或者去新的马棚 4 本题关键在dp初始化INF,由于黑马白马的表示简单,求指数方便 5 */ 6 #include <cstdio> 7 #include <iostream>

递推DP URAL 1586 Threeprime Numbers

题目传送门 1 /* 2 题意:n位数字,任意连续的三位数字组成的数字是素数,这样的n位数有多少个 3 最优子结构:考虑3位数的数字,可以枚举出来,第4位是和第3位,第2位组成的数字判断是否是素数 4 所以,dp[i][j][k] 表示i位数字,最高位数字j,第二高位数字k 5 状态转移方程:dp[i][j][k] += dp[i-1][k][l] 6 注意:最高位从1开始枚举:) 7 详细解释:http://blog.csdn.net/zhangyanxing666/article/detai