/*求1,3/2,5/3,8/5 ,13/8....前N 项之和,以分母为基准*/
#include<iostream>
using namespace std;float f(int n)
{
if(n==1) return 1;
if(n==2) return 2;
return f(n-1)+f(n-2);
}
float fsum(int n)
{
if(n==1) return 1;
if(n==2) return (1+(float)3/2);
return fsum( n-1)+1+f(n-1)/(f(n-2)+f(n-1));
}
int main()
{
cout<< fsum(20)<<endl;
return 0;
}
/*排列的递归*/
#include<iostream>
using namespace std;
int f(int m,int k)
{
if(m<k) return -1;
if(k==1) return m;
return m*f(m-1,k-1);
}
int main()
{
cout<< f(10,3)<<endl;
return 0;
}
// x/1 - x/1*x/2 + x/1*x/2*x/3 - ……
#include<iostream>
using namespace std;
float f(float x,int n)
{
if(n==1) return x;
return f( x, n-1)*(-1)*x/n;//用乘-1*X的方法得项的正负值
}
float fsum(float x,int n)
{
if(n==1) return x;
return fsum( x,n-1)+f( x, n);
}
int main()
{
cout<< fsum(6,8)<<endl;
return 0;
}
////////////////////////////////////////
#include <stdio.h>
#include<stdlib.h>
int f(int x);
int main()
{
int n,x=1;
scanf("%d",n);
while(f(x)<=n)
{
x++;
}
system("pause");
return 0;
}
int f(int x)
{
if(x==1) return 1;
return f(x-1)*3+1 ;
}
///////////////////////////
#include<stdio.h>
char A[3][2];
char a[]={'1','2','3','4','5','6'};
int isok(int k)//分析A[][]当前数与前面的数比较为递归 作准备。
{
int flat=1;
for(int m=0; m<k; m++)
{
if(A[k/2][k%2]==A[m/2][m%2])
flat=0;
}
if(A[k/2][k%2]=='1' && A[k/2][k%2-1]=='3') //1条件
flat=0;
if(A[k/2][k%2]=='3' && A[k/2][k%2-1]=='1') //1条件
flat=0;
if(A[k/2][k%2]=='4' && A[k/2][k%2-1]=='1' )//2
flat=0;
if(A[k/2][k%2]=='1' && A[k/2][k%2-1]=='4' )//2
flat=0;
if(A[k/2][k%2]=='4' && A[k/2][k%2-1]=='3')//3
flat=0;
if(A[0][k%2]=='4'|| A[0][k%2]=='3' )//3
flat=0;
if(A[1][k%2]=='4')//4
flat=0;
if(A[1][k%2]=='1' || A[1][k%2]=='5' )//5
flat=0;
if(A[k/2][k%2]=='1' && A[k/2][k%2-1]=='5')//5
flat=0;
if(A[k/2][k%2]=='5' && A[k/2][k%2-1]=='1' )//5
flat=0;
if(A[k/2][k%2-1]>A[k/2][k%2] )//
flat=0;
return flat;
}
void output()
{
int i,j;
for(i=0; i<3;i++)
{
for(j=0; j<2;j++)
printf("%2c",A[i][j]);
printf("\n");
}
printf("***********************\n");
}
void ok(int n)
{
int j;
if(n==6)
{
output();
return ;
}
for(j=0;j<6;j++)
{
A[n/2][n%2]=a[j];
if(isok(n) ) ok(n+1);
}
}
int main()
{
ok(0);
return 0;
}