ZOJ3538Arrange the Schedule
来源:互联网 发布:苏州淘宝代运营公司 编辑:程序博客网 时间:2024/05/29 10:10
比赛被虐了,一个都不会,这题只要是找出规律,然后要注意的的mod,MOD要用long long 这坑了好久
/*** 时间:2014-9-29** 知识点:** 题意:F(n) = 3/4 * (3^L - (-1)^L) ; D(n) = (3^(L+1) + (-1)^L) / 4 ;*/#include<iostream>#include<cstdio>#include<cstring>#include<map>#include<set>#include<cmath>#include<queue>#include<algorithm>using namespace std;typedef unsigned long long ll;const ll mod=4*1000000007ll;const ll MOD=1000000007ll;int n,m;struct node{ int pos; char c;}g[20];bool cmp(node a,node b){ return a.pos<b.pos;}long long pow_3(int a){ long long res=1; while(a) { //cout<<a<<endl; a--; res*=3; res%=mod; int b=1; long long s=3; while(a-b>=0) { res*=s; res%=mod; s*=s; s%=mod; a-=b; b<<=1; } } return res;}void solve(){ long long ans=1,num; if(m==0) { ans=4*pow_3(n-1)%mod; cout<<ans%MOD<<endl;return; }else{ sort(g,g+m,cmp); ans=pow_3(g[0].pos-1)%mod; ans=(ans*pow_3(n-g[m-1].pos))%mod; for(int i=1;i<m;i++) { int l=g[i].pos-g[i-1].pos-1; if(g[i].c!=g[i-1].c){ //(3^(L+1) + (-1)^L) / 4 num = (((pow_3( l+1 ) -(l&1?1:(-1))) )%mod)/4; ans = ans * num % mod; }else if(g[i].c==g[i-1].c){ // 3/4 * (3^L - (-1)^L) num = ((3*(pow_3( l ) +(l&1?1:(-1))) )%mod)/4; ; ans = ans * num % mod; } } cout<<ans%MOD<<endl; }}int main(){ while(scanf("%d%d",&n,&m)!=EOF){ for(int i=0; i<m; i++) { cin>>g[i].pos>>g[i].c; } solve(); } return 0;}
0 0
- ZOJ3538Arrange the Schedule
- About the schedule
- ZOJ_Arrange the Schedule
- the design of tivoli schedule
- zoj 3538 Arrange the Schedule
- [2014Contest_2I]The Worst Schedule
- zoj 3538 Arrange the Schedule
- Schedule for Final paper of the Undergraduate
- Schedule of the following week(9.24~9.30)
- ZOJ HDU 3538 Arrange the Schedule
- How to schedule the thread's priority?
- [矩阵乘法][动态规划]Arrange the Schedule
- zoj 3538 Arrange the Schedule[矩阵]
- Schedule
- schedule
- schedule
- schedule()
- schedule
- diy特色熊猫面包-Kenwood面包机轻松完成!
- java 获取文件名时乱码
- 数据结构之顺序查找表
- java中的构造方法
- 【BZOJ2243】[SDOI2011]染色 树链剖分
- ZOJ3538Arrange the Schedule
- 小结
- 黑马程序员--java基础
- UVA_297 - Quadtrees
- NGUI官网示例2-interaction-讲解(二)
- PHP创建缩略图
- 栈的压入、弹出序列
- python语言快速入门
- zoj 3640 Help Me Escape 概率dp+dfs记忆化