Codeforces Round 113 (Div. 2)E. Tetrahedron(dp、递推)
题面

链接
题意
从一个顶点出发走过路径长度为n回到出发点的方案总数
题解
考虑dp
\(f[i][0|1|2|3]\):走了i步,现在在j点的方案总数
转移:
\(f[i][0]=f[i-1][1]+f[i-1][2]+f[i-1][3]\)
\(f[i][1]=f[i-1][0]+f[i-1][2]+f[i-1][3]\)
\(f[i][2]=f[i-1][0]+f[i-1][1]+f[i-1][3]\)
\(f[i][3]=f[i-1][0]+f[i-1][1]+f[i-1][2]\)
代码
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
using namespace std;
const int mod=1e9+7;
int dp[3][5];
void solve()
{
int n;
cin>>n;
dp[0][0]=1;
rep(i,1,n){
int u=i&1,v=(i-1)&1;
dp[u][0]=(dp[v][1]+dp[v][2]+dp[v][3])%mod;
dp[u][1]=(dp[v][0]+dp[v][2]+dp[v][3])%mod;
dp[u][2]=(dp[v][0]+dp[v][1]+dp[v][3])%mod;
dp[u][3]=(dp[v][0]+dp[v][1]+dp[v][2])%mod;
}
cout<<dp[n&1][0]<<endl;
}
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
// cin>>_;
// while(_--)
solve();
return 0;
}
总结
一定要开long long,容易忘直接\(define long long int\)
爆空间开滚动数组优化。
Codeforces Round 113 (Div. 2)E. Tetrahedron(dp、递推)的更多相关文章
- Codeforces Round #271 (Div. 2) D. Flowers (递推 预处理)
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all kn ...
- Codeforces Round #113 (Div. 2)
Codeforces Round #113 (Div. 2) B. Polygons 题意 给一个\(N(N \le 10^5)\)个点的凸包 \(M(M \le 2 \cdot 10^4)\)次询问 ...
- Codeforces Round #533 (Div. 2) C.思维dp D. 多源BFS
题目链接:https://codeforces.com/contest/1105 C. Ayoub and Lost Array 题目大意:一个长度为n的数组,数组的元素都在[L,R]之间,并且数组全 ...
- Tetrahedron(Codeforces Round #113 (Div. 2) + 打表找规律 + dp计数)
题目链接: https://codeforces.com/contest/166/problem/E 题目: 题意: 给你一个三菱锥,初始时你在D点,然后你每次可以往相邻的顶点移动,问你第n步回到D点 ...
- Codeforces Round #113 (Div. 2) Tetrahedron(滚动DP)
Tetrahedron time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #131 (Div. 1) B. Numbers dp
题目链接: http://codeforces.com/problemset/problem/213/B B. Numbers time limit per test 2 secondsmemory ...
- Codeforces Round #131 (Div. 2) B. Hometask dp
题目链接: http://codeforces.com/problemset/problem/214/B Hometask time limit per test:2 secondsmemory li ...
- Codeforces Round #276 (Div. 1) D. Kindergarten dp
D. Kindergarten Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/proble ...
- Codeforces Round #260 (Div. 1) A - Boredom DP
A. Boredom Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/455/problem/A ...
- Codeforces Round #539 (Div. 2) 异或 + dp
https://codeforces.com/contest/1113/problem/C 题意 一个n个数字的数组a[],求有多少对l,r满足\(sum[l,mid]=sum[mid+1,r]\), ...
随机推荐
- Windows 10 关闭搜索栏中“热门搜索”的显示。
Windows 10 关闭搜索栏中"热门搜索"的显示. 任务栏取消"显示搜索突出显示"的设置可能无法取消"热门搜索"的显示, 这就需要您尝试 ...
- C# 使用字典将枚举转换为String
枚举 public enum ColorType { Red = 10, Blue = 20, Green = 30, Yellow = 40, } String var A1 = "AAA ...
- 用Unity3D做游戏开发在Android上的常用调试方法
Hdg Remote Debug 远程调试 游戏运行在手机上,可以通过pc端的unity来随时修改当前场景中GameObject的变量,从而改变手机上运行时的表现.比如,我可以勾掉下图中的" ...
- [转发]MySQL安装配置教程(超级详细、保姆级)
MySQL安装配置教程(超级详细.保姆级)_SoloVersion的博客-CSDN博客_mysql安装配置教程一. 下载MySQLMysql官网下载地址https://downloads.mysql. ...
- 10.2 调试事件获取DLL装载
理解了如何通过调试事件输出当前进程中寄存器信息,那么实现加载DLL模块也会变得很容易实现,加载DLL模块主要使用LOAD_DLL_DEBUG_EVENT这个通知事件,该事件可检测进程加载的模块信息,一 ...
- 物联网浏览器(IoTBrowser)-Modbus协议集成和测试
Modbus协议在应用中一般用来与PLC或者其他硬件设备通讯,Modbus集成到IoTBrowser使用串口插件模式开发,不同的是采用命令函数,具体可以参考前面几篇文章.目前示例实现了Modbus-R ...
- 内存泄漏定位工具之 mtrace(二)
1 前言 mtrace(memory trace),是 GNU Glibc 自带的内存问题检测工具,它可以用来协助定位内存泄露问题.它的实现源码在glibc源码的malloc目录下,其基本设计原理为设 ...
- Exadata存储节点的CPU限制成功了没?
上篇随笔谈到刷1/8 rack时,日志显示存储节点已经成功限制CPU的,可如果使用mpstat命令看貌似还是64 CPU,难道实际没有成功吗? [root@dbm08celadm03 ~]# mpst ...
- IIS的详细配置
一:配置默认文档 输入ip打开哪个页面是由默认文档设定的 1.打开IIS配置页面,点击网站.我们的默认站点已经启动,可以看到绑定的ip和网页的路径 2.选中Default Web Site,可以看到有 ...
- Linux查看系统版本的方法
记录几种查看当前Linux系统的版本的方法 一.使用命令:cat /proc/version 查看 linux版本号:Linux version 5.4.0-99-generic (buildd@lg ...