2/26 5x5的圖形請算出左上至右下不重複路線數量及路線
本帖最後由 justtim 於 2011-2-26 21:37 編輯
如果不是5x5 就將tra函數多加兩個參數x_end , y_end- #include<iostream>
- #include<sstream>
- using namespace std ;
- int all = 0 ;
- void tra( int x , int y , string ta )
- {
- if( x == 5 && y == 5 )
- {
- all ++ ;
- cout << ta << "(" << x << "," << y << ")" << endl ;
- }
- else
- {
- stringstream st ;
- st << ta << "(" << x << "," << y << ")" ;
-
- if( x < 5 )
- {
- tra( x + 1 , y , st.str() ) ;
- }
- if( y < 5 )
- {
- tra( x , y + 1 , st.str() ) ;
- }
- }
- }
- int main()
- {
- tra( 0 , 0 , "" ) ;
- cout << all << endl ;
- system( "Pause" ) ;
- }
複製代碼 |