hdu5241——Friends(找规律+大数幂)

Friends

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1326    Accepted Submission(s): 623


Problem Description
Mike has many friends. Here are nine of them: Alice, Bob, Carol, Dave, Eve, Frank, Gloria, Henry and Irene.

Mike is so skillful that he can master n languages (aka. programming languages).

His nine friends are all weaker than he. The sets they can master are all subsets of Mike's languages.

But the relations between the nine friends is very complex. Here are some clues.

1. Alice is a nice girl, so her subset is a superset of Bob's.
2. Bob is a naughty boy, so his subset is a superset of Carol's.
3. Dave is a handsome boy, so his subset is a superset of Eve's.
4. Eve is an evil girl, so her subset is a superset of Frank's.
5. Gloria is a cute girl, so her subset is a superset of Henry's.
6. Henry is a tall boy, so his subset is a superset of Irene's.
7. Alice is a nice girl, so her subset is a superset of Eve's.
8. Eve is an evil girl, so her subset is a superset of Carol's.
9. Dave is a handsome boy, so his subset is a superset of Gloria's.
10. Gloria is a cute girl, so her subset is a superset of Frank's.
11. Gloria is a cute girl, so her subset is a superset of Bob's.

Now Mike wants to know, how many situations there might be.
 

Input
The first line contains an integer T ( T20 ) denoting the number of test cases.

For each test case, the first line contains an integer n ( 0n3000 ), denoting the number of languages.

 

Output
For each test case, output ''Case #t:'' to represent this is the t-th case. And then output the answer.
 

Sample Input
  
  
2 0 2
 

Sample Output
  
  
Case #1: 1 Case #2: 1024
 

Source

Mike 有很多朋友,他们的名字叫Alice, Bob, Carol, Dave, Eve, Frank, Gloria, Henry and Irene. 
Mike会n种语言, 他的朋友会的语言数目都是Mike的子集 
并且他的朋友有以下关系: 
1.Alice 是Bob 的子集 
2.Bob 是Carol 的子集 
3.Dave 是Eve 的子集 
4.Eve 是Frank 的子集 
5.Gloria是Henry的子集 
6.Henry是Irene 的子集 
7.Alice 是Eve 的子集 
8.Eve 是Carol 的子集 
9.Dave 是Gloria的子集 
10.Gloria是Frank的子集 
11.Gloria是Bob 的子集 
现在Mike想知道有多少种可能?
对于每一种语言来说,这种语言谁会谁不会是的方案数一定,而且语言之间相互独立的,互相之间通过乘法原理来计算方案数,这样就一定是某一个数的n次方 (确切是2的多少次方)
后来把人物关系画成拓扑关系,不难发现里边最长的拓扑关系是五个人的,就这五个人,语言数就确定了(2^5)^n (其他的人拓扑关系没这么长,他们会的语言数一定是最大范围的子集)
数据太大,不用大数不行,百了一个大数幂模板贴上AC了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <stack>
using namespace std;
typedef long long ll;
#define PI 3.1415926535897932
#define E 2.718281828459045
#define INF 0xffffffff//0x3f3f3f3f
#define mod 100


const int M=1005;
int n,m;
int cnt;
int sx,sy,sz;
int mp[1000][1000];
int pa[M*10],rankk[M];
int head[M*6],vis[M*100];
int dis[M*100];
int prime[M*1000];
bool isprime[M*1000];
int lowcost[M],closet[M];
char st1[5050],st2[5050];
//int len[M*6];
typedef pair<int ,int> ac;
int dp[55][55][55][55];
int has[1050000];
int month[13]= {0,31,59,90,120,151,181,212,243,273,304,334,0};
int dir[8][2]= {{0,1},{0,-1},{-1,0},{1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
void getpri()
{
    int i;
    int j;
    cnt=0;
    memset(isprime,false,sizeof(isprime));
    for(i=2; i<1005; i++)
    {
        if(!isprime[i])prime[cnt++]=i;
        for(j=0; j<cnt&&prime[j]*i<10000; j++)
        {
            isprime[i*prime[j]]=1;
            if(i%prime[j]==0)break;
        }
    }
}
struct node
{
    int v,w;
    node(int vv,int ww)
    {
        v=vv;
        w=ww;
    }
};
vector<int> g[100005];
char str[10005];
int bit[50];
int num[100005] ;
int len ;
void solve(int n)
{
    memset(num ,0,sizeof(num)) ;
    num[1] = 1;
    len = 1;
    for(int i = 1; i <=n ; i++)
    {
        int c = 0 ;
        for(int j = 1; j <= len; j++)
        {
            num[j] *= 32 ;
            num[j] += c ;
            c = num[j]/mod ;
            num[j] %= mod ;
        }
        while(c)
        {
            num[++len] = c%mod ;
            c/=mod ;
        }
    }
}
int main()
{
    int t,i,j,k;
    int cas =0 ;
    scanf("%d",&t) ;
    while(t--)
    {
        int n  ;
        scanf("%d",&n) ;
        solve(n) ;
        printf("Case #%d: " , ++cas) ;
        for(i = len; i > 0; i--)
        {
            if(i!=len)
                printf("%02d" ,num[i]) ;
            else
                printf("%d" , num[i]) ;
        }
        printf("\n");
    }
}
 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值