找规律 UVALive 6506 Padovan Sequence

题目传送门

 1 /*
 2     找规律:看看前10项就能看出规律,打个表就行了。被lld坑了一次:(
 3 */
 4 #include <cstdio>
 5 #include <algorithm>
 6 #include <iostream>
 7 #include <cstring>
 8 #include <cmath>
 9 #include <string>
10 #include <vector>
11 #include <queue>
12 #include <map>
13 #include <set>
14 #include <ctime>
15 #include <cstdlib>
16 using namespace std;
17
18 typedef long long ll;
19 const int MAXN = 1e2 + 10;
20 const int INF = 0x3f3f3f3f;
21 ll dp[MAXN];
22
23 void solve(void)
24 {
25     dp[1] = dp[2] = dp[3] = 1;
26     dp[4] = dp[5] = 2;    dp[6] = 3;
27     for (int i=7; i<=100; ++i)
28     {
29         dp[i] = dp[i-1] + dp[i-5];
30     }
31 }
32
33 int main(void)        //UVALive 6506 Padovan Sequence
34 {
35 //    freopen ("G.in", "r", stdin);
36
37     solve ();
38     int t;    scanf ("%d", &t);
39     while (t--)
40     {
41         int n;    scanf ("%d", &n);
42         printf ("%lld\n", dp[n]);
43     }
44
45     return 0;
46 }
时间: 2024-11-06 15:36:54

找规律 UVALive 6506 Padovan Sequence的相关文章

DP UVALive 6506 Padovan Sequence

题目传送门 /* 题意:两行数字,相邻列一上一下,或者隔一列两行都可以,从左到右选择数字使和最大 DP:状态转移方程:dp[i][j] = max (dp[i][j], dp[1-i][j-1] + a[i][j], dp[i/1-i][j-2] + a[i][j]); 要从前面一个转态推过来啊,我比赛写反了,内功不够:( */ #include <cstdio> #include <algorithm> #include <iostream> #include <

找规律/hdu 1005 Number Sequence

题意 给出a,b,n,已知f[1]=f[2]=1,f[i]=(a*f[i-1]+b*f[i-2]) mod 7 输出f[n] 数据范围 1 <= A, B <= 1000, 1 <= n <= 100,000,000 分析 首先,直接求..肯定是不行的 会tle 会mle 但是可以找到规律,例如对a=1,b=1 这个数据,有 f1=1 f2=1 f3=3 f4=5 f5=4 f6=0 f7=1 f8=1 f9=3 f10=5 f11=4 f12=0 ???? 我们会发现有一定的规律

UVALive 6270 Edge Case(找规律,大数相加)

转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 找规律,前两个数的和等于后一个数的值: 其实就是大菲波数: 代码如下: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #include<cstdio> #include<cst

uva10706 - Number Sequence(找规律)

题目:uva10706 - Number Sequence(找规律) 题目大意:有这样一串序列11212312341234512345612345671234567812345678912345678910123456789101112345678910...,问第i个位置数的值. 1  2     3       4          5            6              7               ... 解题思路:这题需要发现规律.我一开始还看错题意了.规律是看了别人

UVaLive 6847 Zeroes (找规律,水题)

题意 :给定一个范围,然后让你求在这个范围内所有的数的阶乘末尾0的个数有多少种. 析:找规律,写几个就会发现每隔5个会增加一个0,因为要么乘10了,要么乘5了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #inclu

UVALive - 3722 找规律

题意:找规律 题解:找规律 结论是\(a^n(x-1)-\sum_{i=1}^{n-1}a^i \mod\ c\) #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<string> #include<vector> #includ

The Cow Lineup_找规律

Description Farmer John's N cows (1 <= N <= 100,000) are lined up in a row.Each cow is labeled with a number in the range 1...K (1 <= K <=10,000) identifying her breed. For example, a line of 14 cows might have these breeds: 1 5 3 2 5 1 3 4 4

玲珑杯热身赛A--Alarm (找规律)

DESCRIPTION Given a number sequence [3,7,22,45,116,...][3,7,22,45,116,...]. Please tell me the kk-th number. INPUT A number T (T<100)T (T<100) indicates the number of the input cases. Then for each case there only is one integer k (1≤k≤10000)k (1≤k≤

HDU 1564 Play a game (博弈&amp;&amp;找规律)

Play a game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1430    Accepted Submission(s): 1168 Problem Description New Year is Coming! ailyanlu is very happy today! and he is playing a chessbo