当前位置:网站首页>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;
}
边栏推荐
- Dark horse -- redis
- Pychrm Community Edition calls matplotlib pyplot. Solution of imshow() function image not popping up
- Druid database connection pool details
- [pytorch] yolov5 train your own data set
- R language uses rchisq function to generate random numbers that conform to Chi square distribution, and uses plot function to visualize random numbers that conform to Chi square distribution
- map的使用(列表的数据赋值到表单,json逗号隔开显示赋值)
- C language daily practice - day 22: Zero foundation learning dynamic planning
- test about BinaryTree
- Mathematical knowledge -- code implementation of Gaussian elimination (elementary line transformation to solve equations)
- 思维导图+源代码+笔记+项目,字节跳动+京东+360+网易面试题整理
猜你喜欢
MRO industrial products enterprise procurement system: how to refine procurement collaborative management? Industrial products enterprises that want to upgrade must see!
零基础入门PolarDB-X:搭建高可用系统并联动数据大屏
Problems encountered in using RT thread component fish
Php+redis realizes the function of canceling orders over time
In depth analysis, Android interview real problem analysis is popular all over the network
潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
A full set of teaching materials, real questions of Android interview of 7 major manufacturers including Alibaba Kwai pinduoduo
Dark horse -- redis
Cereals Mall - Distributed Advanced p129~p339 (end)
A popular explanation will help you get started
随机推荐
应用使用Druid连接池经常性断链问题分析
五金机电行业供应商智慧管理平台解决方案:优化供应链管理,带动企业业绩增长
Countdown 2 days | live broadcast preview of Tencent cloud message queue data import platform
Intelligent supply chain management system solution for hardware and electromechanical industry: digital intelligent supply chain "creates new blood" for traditional industries
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图
业务与应用同步发展:应用现代化的策略建议
USB host driver - UVC swap
Sanmian ant financial successfully got the offer, and has experience in Android development agency recruitment and interview
short i =1; i=i+1与short i=1; i+=1的区别
JDBC details
How word displays modification traces
[pytorch] yolov5 train your own data set
凤凰架构3——事务处理
The dplyr package of R language performs data grouping aggregation statistical transformations and calculates the grouping mean of dataframe data
Dark horse -- redis
R language ggplot2 visualization: use the ggdotplot function of ggpubr package to visualize dot plot, set the palette parameter, and set the colors of data points and box graphs of dot plots at differ
C # use Marshall to manually create unmanaged memory in the heap and use
R language uses rchisq function to generate random numbers that conform to Chi square distribution, and uses plot function to visualize random numbers that conform to Chi square distribution
tensorflow和torch代码验证cuda是否安装成功
In 50W, what have I done right?