题目描述
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.
![](https://i-blog.csdnimg.cn/blog_migrate/8efcd3a345fccae683ca537d20932808.png)
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.
![](https://i-blog.csdnimg.cn/blog_migrate/6daf8be361a80ff752568239151fac7e.png)
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;
}