题目描述
Fox Ciel wants to write a task for a programming contest. The task is: "You are given a simple undirected graph with n vertexes. Each its edge has unit length. You should calculate the number of shortest paths between vertex 1 and vertex 2."
Same with some writers, she wants to make an example with some certain output: for example, her birthday or the number of her boyfriend. Can you help her to make a test case with answer equal exactly to k?
解题思路
代码
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 bool map[1005][1005]; 7 inline void add(int f,int t){ 8 map[t][f]=map[f][t]=1; 9 } 10 inline void ini(){ 11 add(1,3),add(1,4),add(2,100); 12 for(register int i=3;i<60;i+=2)add(i,i+2),add(i,i+3),add(i+1,i+2),add(i+1,i+3); 13 for(register int i=63;i<100;i++)add(i,i+1); 14 } 15 int main(){ 16 ini(); 17 int k; 18 cin>>k; 19 for(register int i=30;i;i--){ 20 if(k>=(1<<i)){ 21 k-=(1<<i); 22 add(2*i+1,63+i),add(2*i+2,63+i); 23 } 24 } 25 if(k)add(1,63); 26 cout<<100<<endl; 27 for(register int i=1;i<=100;i++){ 28 for(register int j=1;j<=100;j++){ 29 if(map[i][j])putchar('Y'); 30 else putchar('N'); 31 } 32 putchar('\n'); 33 } 34 return 0; 35 }