Advertisement
XuanHong

LTTS - bài toán số cách đi con xe mở rộng

Jan 26th, 2015
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. // LTTS - bài toán số cách đi con xe mở rộng
  2.  
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int a[100][100] = {0};
  7. int b[100][100] = {0};
  8. int c[100][100] = {0};
  9. int n;
  10.  
  11. int main()
  12. {  
  13.     cout<<"Nhap kich thuoc ban co: "<<endl;
  14.     cin>>n;
  15.    
  16.     for(int i=0; i<n; i++)
  17.     {
  18.         a[0][i]=1;
  19.         a[i][0]=1;
  20.         b[0][i]=1;
  21.         b[i][0]=1;
  22.         c[0][i]=1;
  23.         c[i][0]=1;
  24.     }
  25.  
  26.     for(int i=1; i< n; i++)
  27.     {
  28.         for(int j=1; j<n; j++)
  29.         {
  30.             a[i][j]=a[i-1][j]+a[i][j-1];           
  31.         }      
  32.     }
  33.  
  34.     for(int i=0; i<n; i++)
  35.     {
  36.         for(int j=0; j<n; j++)
  37.         {          
  38.             b[i][j]=b[i-1][j]+b[i][j-1]+a[i][j];
  39.             c[i][j]=c[i-1][j]+c[i][j-1]+b[i][j];
  40.         }      
  41.     }
  42.  
  43.     cout<<"So cach di con xe (khoi lap phuong): "<<c[n-1][n-1]<<endl;
  44.  
  45.     return 1;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement