Codeforces 166E Tetrahedron(dp)
来源:互联网 发布:java线程注入service 编辑:程序博客网 时间:2024/06/06 13:58
题意:
给你一个正四面体,问你从定点出发走k步后回到定点有几种走法。我反正是不会做,看了CF的题解才明白具体怎么写。我们只需要两个变量,记录当前步数下,走到定点和到其他三个点的种数就好。具体看代码理解。
代码:
//// Created by CQU_CST_WuErli// Copyright (c) 2015 CQU_CST_WuErli. All rights reserved.//// #include<bits/stdc++.h>#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <cctype>#include <cmath>#include <string>#include <vector>#include <list>#include <map>#include <queue>#include <stack>#include <set>#include <algorithm>#include <sstream>#define CLR(x) memset(x,0,sizeof(x))#define OFF(x) memset(x,-1,sizeof(x))#define MEM(x,a) memset((x),(a),sizeof(x))#define For_UVa if (kase!=1) cout << endl#define BUG cout << "I am here" << endl#define lookln(x) cout << #x << "=" << x << endl#define SI(a) scanf("%d",&a)#define SII(a,b) scanf("%d%d",&a,&b)#define SIII(a,b,c) scanf("%d%d%d",&a,&b,&c)#define rep(flag,start,end) for(int flag=start;flag<=end;flag++)#define Rep(flag,start,end) for(int flag=start;flag>=end;flag--)#define Lson l,mid,rt<<1#define Rson mid+1,r,rt<<1|1#define Root 1,n,1#define BigInteger bigntemplate <typename T> T gcd(const T& a,const T& b) {return b==0?a:gcd(b,a%b);}const int MAX_L=2005;// For BigIntegerconst int INF_INT=0x3f3f3f3f;const long long INF_LL=0x7fffffff;const int MOD=1e9+7;const double eps=1e-9;const double pi=acos(-1);typedef long long ll;using namespace std;int n;int main(){#ifdef LOCAL// freopen("C:\\Users\\john\\Desktop\\in.txt","r",stdin);// freopen("C:\\Users\\john\\Desktop\\out.txt","w",stdout);#endif while (SI(n)==1) { ll inABC,inD; inD=1; inABC=0; for (int i=1;i<=n;i++) { ll toD=(inABC*3)%MOD; // 到定点可以从另外三个点走,所以乘以3。 ll toABC=(inABC*2+inD)%MOD; // 到三个下面的点之一可以从另外两个点和定点走,所以乘2+定点的。 inD=toD; inABC=toABC; } cout << inD << endl; } return 0;}
0 0
- Codeforces 166E Tetrahedron(dp)
- codeforces 166-E. Tetrahedron(预处理+dp)
- codeforces 166e Tetrahedron 水dp
- CodeForces 166E Tetrahedron
- CodeForces 166E Tetrahedron
- Codeforces 166E Tetrahedron
- CodeForces 166E Tetrahedron
- CodeForces 166E Tetrahedron
- codeforces 166E Tetrahedron 数学题
- CodeForces 166E -Tetrahedron解题报告
- Codeforces Round #113 (Div. 2) E. Tetrahedron dp
- CF problem 166E Tetrahedron
- E. Tetrahedron
- Codeforces Round #113 (Div. 2)E---Tetrahedron(矩阵,水题)
- CodeForces - 49E Common ancestor(dp)
- CodeForces 148E Porcelain(dp+背包)
- Codeforces 598E:Chocolate Bar(DP)
- Codeforces 148E Porcelain (dp)
- 【poj 1273】Drainage Ditches (最大流裸题)
- WC2016酱油记
- BZOJ-1196 公路修建问题 最小生成树Kruskal+(二分??)
- HDU 5616 Jam's balance(dp)
- POJ 2010 Moo University-Financial Aid
- Codeforces 166E Tetrahedron(dp)
- 四种进程或线程同步互斥的方法:临界区、互斥对象、事件对象、信号量
- 2.4.2认识分支结构-if语句
- spring 测试测试
- 英语总结
- 米老师语录
- 2.4.3认识循环结构-while语句
- SQL Server 2012 导出数据及分离MDF、LDF
- 2.4.4认识循环结构-for语句