http://codeforces.com/contest/584/problem/B
题意:给一个n,表示一张桌子坐了3*n个人
你要给每一个人发钱,可以发1,2,3块,第i个人的钱是ai (i从0开始)
有一个要求:. If there is an integer i(0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied.
也就是只要有 一组that ai + ai + n + ai + 2n ≠ 6, .就可以了
显然 ai a(i+n) a(i+2n)是一个三角形....
对于n=1的时候,我们可以发现这个三角形有 20种情况符合条件,7种不符合条件;
当n为其他情况的时候,我们分成2种情况:
【1】 第一个三角形是20种的一种,那么剩下n-1个三角形 可以是27种情况任意一种。。 总方案数 20* 27^(n-1)
【2】第一个三角形是7种的一种,那么剩下n-1个三角形至少要有1个是符合要求的.
也就是有7 * (C(n-1,1)*(20^1)*(7^[n-1-1]) + c(n-1,2)*(20^2)*(7^[n-1-2] ) + .....+c(n-1,n-1) * 20^(n-1) )
后面部分就是二项式展开啦。。。所以最后是7* (20+7)^(n-1) -C(n-1,0)*7^(n-1) //减去全部不合法的情况
答案就是【1】+【2】
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;
const __int64 mod =1000000007;
__int64 fast_m(__int64 a,__int64 b)
{
__int64 x,ans=1;
x=a;
while(b)
{
if (b&1)
ans=(ans*x)%mod;
x=(x*x)%mod;
b/=2;
}
return ans;
}
int main()
{
__int64 i;
__int64 n;
scanf("%I64d",&n);
/* if (n==1)
{
printf("20\n");
return 0;
}
*/
__int64 ans=(20*fast_m(27,n-1))%mod;
__int64 tmp= fast_m(20+7,n-1)-fast_m(7,n-1);
if (tmp<0)
tmp+=mod;
ans=(ans+7*tmp)%mod;
printf("%I64d\n",ans);
return 0;
}