当前位置:网站首页>Lick the dog until the last one has nothing (simple DP)
Lick the dog until the last one has nothing (simple DP)
2022-07-06 19:24:00 【surowvv】
Title Description
As the core of the team ,forever97 He is respected by the other two teammates .
Trote_w Please... Every day forever97 Take out , But unfortunately, the center of the universe forever97 There are only 3 home forever97 Favorite takeout .
If Trote_w to forever97 Bought takeout from another family ,forever97 Will shout “ I don't eat I don't eat ”.
however forever97 I don't like to eat a takeout for three days in a row .
If Trote_w One day I forgot about it and bought him the same takeout for three days , that forever97 It will Trote_w Press your head into the screen of your mobile phone .
As Trote_w Good friends , You can tell him to keep asking forever97 eat n Tianfan , How many different ways to buy ?
Input description :
Multiple sets of samples The first line is an integer T(1<=T<=20) Represents the number of test samples Next t Each row is an integer n, representative Trote_w Please forever97 eat n Tianfan (1<=n<=100000)
Output description :
Output T An integer represents the number of schemes , Because the answer is too big , You just need to output mod 1e9+7 The answer after .
Example 1
Input
2
3
500
Output
24
544984352
analysis :
about a,b,c Three takeaways , Hypothesis number 1 i God eat a, Then the number of schemes is i-1 God eat a+ The first i-1 God eat b+ The first i-1 God eat c;
Among them the first i-1 God eat a when , The first i-2 It's impossible to eat a, Can only eat b or c.
So the first i God eat a Number of schemes Actually, it is No i-2 God eat b+ The first i-2 God eat c+ The first i-1 God eat b+ The first i-1 God eat c;
The same goes for the other two takeout .
The first i God eat b Number of schemes Actually, it is No i-2 God eat a+ The first i-2 God eat c+ The first i-1 God eat a+ The first i-1 God eat c;
The first i God eat c Number of schemes Actually, it is No i-2 God eat a+ The first i-2 God eat b+ The first i-1 God eat a+ The first i-1 God eat b;
All in all , The first i Number of prescriptions = The first i-2 Number of prescriptions *2+ The first i-1 Number of prescriptions *2;
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
int f[100010];
int main()
{
int T;
cin >> T;
f[1] = 3, f[2] = 9;
while (T--) {
int x;
cin >> x;
for (int i = 3; i <= x; i++) f[i] = (f[i - 1] + f[i - 2]) % mod * 2 % mod;
cout << f[x] << endl;
}
return 0;
}边栏推荐
- It's super detailed in history. It's too late for you to read this information if you want to find a job
- 思維導圖+源代碼+筆記+項目,字節跳動+京東+360+網易面試題整理
- Benefit a lot, Android interview questions
- Swagger2 reports an error illegal DefaultValue null for parameter type integer
- Elastic search indexes are often deleted [closed] - elastic search indexes gets deleted frequently [closed]
- A full set of teaching materials, real questions of Android interview of 7 major manufacturers including Alibaba Kwai pinduoduo
- R language ggplot2 visualization: use the ggstripchart function of ggpubr package to visualize the grouped dot strip plot, and set the add parameter to add box plots for different levels of dot strip
- 深入分析,Android面试真题解析火爆全网
- R语言dplyr包进行数据分组聚合统计变换(Aggregating transforms)、计算dataframe数据的分组均值(mean)
- 五金机电行业智能供应链管理系统解决方案:数智化供应链为传统产业“造新血”
猜你喜欢

10 schemes to ensure interface data security

五金机电行业智能供应链管理系统解决方案:数智化供应链为传统产业“造新血”

LeetCode-1279. 红绿灯路口

zabbix 代理服务器 与 zabbix-snmp 监控

Computer network: sorting out common network interview questions (I)

Pytorch common loss function

ZABBIX proxy server and ZABBIX SNMP monitoring

系统性详解Redis操作Hash类型数据(带源码分析及测试结果)
受益匪浅,安卓面试问题

Lucun smart sprint technology innovation board: annual revenue of 400million, proposed to raise 700million
随机推荐
R语言使用order函数对dataframe数据进行排序、基于单个字段(变量)进行降序排序(DESCENDING)
R language ggplot2 visualization: use the ggstripchart function of ggpubr package to visualize the grouped dot strip plot, and set the add parameter to add box plots for different levels of dot strip
Swagger2 reports an error illegal DefaultValue null for parameter type integer
Tongyu Xincai rushes to Shenzhen Stock Exchange: the annual revenue is 947million Zhang Chi and Su Shiguo are the actual controllers
Analysis of frequent chain breaks in applications using Druid connection pools
Graffiti intelligence is listed on the dual main board in Hong Kong: market value of 11.2 billion Hong Kong, with an annual revenue of 300 million US dollars
A popular explanation will help you get started
GCC [7] - compilation checks the declaration of functions, and link checks the definition bugs of functions
JDBC详解
map的使用(列表的数据赋值到表单,json逗号隔开显示赋值)
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图
zabbix 代理服务器 与 zabbix-snmp 监控
spark基础-scala
Reflection and illegalaccessexception exception during application
It's super detailed in history. It's too late for you to read this information if you want to find a job
打家劫舍III[后序遍历与回溯+动态规划]
Synchronous development of business and application: strategic suggestions for application modernization
Fast power template for inverse element, the role of inverse element and example [the 20th summer competition of Shanghai University Programming League] permutation counting
冒烟测试怎么做
Benefit a lot, Android interview questions