SDUT 1498 Edge Case

题目描述

 In graph theory, a matching or independent edge set in a graph G = (V, E) is a set of edges M ⊆ E such that no two edges in the matching M share a common vertex. Recently you saw in the news that “The Sveriges Riksbank Prize in Economic Sciences in Memory of Alfred Nobel” (informally, the Nobel Prize in Economics) for 2012 was awarded to Alvin E. Roth and Lloyd S. Shapley for, amongst other things, their algorithm for finding a matching satisfying certain criteria in a bipartite graph. Since you have also heard that matchings in cycle graphs have applications in chemistry your thoughts centre around a plan for a beautiful future where your Christmas shopping is more luxurious than ever!
The cycle graph, Cn , n ≥ 3, is a simple undirected graph, on vertex set {1, . . . , n}, with edge set E(Cn ) = {{a, b} | |a − b| ≡ 1 mod n}. It is 2-regular, and contains n edges. The graphs C3 , C4 , C5 , and C6 are depicted in Figure 1.

Your first step towards Nobel Prize fame is to be able to compute the number of matchings in the cycle graph Cn . In Figure 2 the seven matchings of the graph C4 are depicted.

Figure 2: The matchings of C4 . The edges that are part of the respective matching are coloured green, while the edges left out of the matching are dashed. M1 = ∅,M2 = {{2, 1}}, M3 = {{3, 2}}, M4 = {{4, 3}}, M5 = {{1, 4}}, M6 = {{2, 1}, {4, 3}}, and M7 = {{3, 2}, {1, 4}}.
 
 

输入

 For each test case, you get a single line containing one positive integer: n, with 3 ≤ n ≤ 10000.

输出

 For each test case, a row containing the number of matchings in Cn .
 

示例输入

3 
4 
100 

示例输出

4
7
792070839848372253127
 
   原来是找规律,大数斐波那契啊
#include <stdio.h>
#include <string.h>
int s1[100000],s2[100000];
int sum[100000];
int main()
{
    int i,j,n,m,s,t,x;
    int l1,l2,min;
    while(scanf("%d",&n)!=EOF)
    {
        if(n==3)
        {
            printf("4\n");
            continue;
        }else if(n==4)
        {
            printf("7\n");
            continue;
        }
        s1[0]=4;
        s2[0]=7;
        l1=l2=1;
        for(i=5;i<=n;i++)
        {
            for(j=0;j<=l1-1&&j<=l2-1;j++)
            {
                sum[j]=s1[j]+s2[j];
            }
            for(;j<=l1-1;j++)
            {
                sum[j]=s1[j];
            }
            for(; j<=l2-1;j++)
            {
                sum[j]=s2[j];
            }
            for(x=0;x<=j-1;x++)
            {
                if(sum[x]>=10)
                {
                    if(x==j-1)
                    {
                        sum[x]-=10;
                        sum[x+1]=1;
                        j++;
                    }else
                    {
                        sum[x]-=10;
                        sum[x+1]+=1;
                    }
                }
            }
            for(x=0;x<=l2-1;x++)
            {
                s1[x]=s2[x];
            }
            for(x=0;x<=j-1;x++)
            {
                s2[x]=sum[x];
            }
            l1=l2;
            l2=j;
        }
        for(i=l2-1;i>=0;i--)
        {
            printf("%d",s2[i]);
        }
        printf("\n");
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值