具體程式::// mn.cpp : Defines the entry point for the console application.
//
#include <iostream.h>
#include <stdio.h>
#include <stack>
using namespace std;
typedef const __int64 ll;
typedef struct point{
int x, y;
}point;
stack<point> sp;
const int MAXN = 20;
int g[MAXN][MAXN];
point vp[MAXN+MAXN];
ll path(ll m, ll n){
if(m == 1 || n == 1) return 1;
else return path(m-1, n) + path(m, n-1);
}
ll fact(ll n){
if(n == 0) return 1;
else return n*fact(n-1);
}
ll path1(ll m, ll n){
return fact(m-1+n-1)/(fact(m-1)*fact(n-1));
}
bool get_path(int m, int n){
point p; p.x=n; p.y=m;
sp.push(p);
if(n==1 && m==1) return true;
bool suc = false;
if(m>1 && g[m-1][n])
suc = get_path(m-1, n);
if(!suc && n>1 && g[m][n-1])
suc = get_path(m, n-1);
if(!suc) sp.pop();
return suc;
}
void print_paths(int m, int n, int M, int N, int len){
if(g[m][n] == 0) return;
point p; p.x=n; p.y=m;
vp[len++] = p;
if(m == M && n == N){
for(int i=0; i<len; ++i)
cout<<"("<<vp[i].y<<", "<<vp[i].x<<")"<<" ";
cout<<endl;
}
else{
print_paths(m, n+1, M, N, len);
print_paths(m+1, n, M, N, len);
}
}
int main(){
freopen("8.2.in", "r", stdin);
for(int i=1; i<10; ++i)
cout<<path(i, i)<<endl;
cout<<endl;
for(int i=1; i<10; ++i)
cout<<path1(i, i)<<endl;
cout<<endl;
int M, N;
cin>>M>>N;
for(int i=1; i<=M; ++i)
for(int j=1; j<=N; ++j)
cin>>g[i][j];
cout<<"one of the paths:"<<endl;
get_path(M, N);
while(!sp.empty()){
point p = sp.top();
cout<<"("<<p.y<<", "<<p.x<<")"<<" ";
sp.pop();
}
cout<<endl<<"all paths:"<<endl;
print_paths(1, 1, M, N, 0);
fclose(stdin);
return 0;
}
uj5u.com熱心網友回復:
缺相應物件的operator <<的實作。uj5u.com熱心網友回復:
頭檔案改一下#include <iostream>
uj5u.com熱心網友回復:
不對啊,會出現錯誤:Compiling...
mn.cpp
f:\博士\程式\mn\mn.cpp(48) : error C2065: 'cout' : undeclared identifier
f:\博士\程式\mn\mn.cpp(48) : error C2297: '<<' : illegal, right operand has type 'char [2]'
f:\博士\程式\mn\mn.cpp(49) : error C2065: 'endl' : undeclared identifier
f:\博士\程式\mn\mn.cpp(49) : warning C4552: '<<' : operator has no effect; expected operator with side-effect
f:\博士\程式\mn\mn.cpp(59) : warning C4552: '<<' : operator has no effect; expected operator with side-effect
f:\博士\程式\mn\mn.cpp(60) : warning C4552: '<<' : operator has no effect; expected operator with side-effect
f:\博士\程式\mn\mn.cpp(62) : warning C4552: '<<' : operator has no effect; expected operator with side-effect
f:\博士\程式\mn\mn.cpp(63) : warning C4552: '<<' : operator has no effect; expected operator with side-effect
f:\博士\程式\mn\mn.cpp(65) : error C2065: 'cin' : undeclared identifier
f:\博士\程式\mn\mn.cpp(65) : warning C4552: '>>' : operator has no effect; expected operator with side-effect
f:\博士\程式\mn\mn.cpp(68) : warning C4552: '>>' : operator has no effect; expected operator with side-effect
f:\博士\程式\mn\mn.cpp(69) : error C2297: '<<' : illegal, right operand has type 'char [18]'
f:\博士\程式\mn\mn.cpp(73) : error C2297: '<<' : illegal, right operand has type 'char [2]'
f:\博士\程式\mn\mn.cpp(76) : error C2297: '<<' : illegal, right operand has type 'char [11]'
執行 cl.exe 時出錯.
mn.obj - 1 error(s), 0 warning(s)
uj5u.com熱心網友回復:
typedef const __int64 ll; 型別不對改為:
typedef const int ll;
試試
uj5u.com熱心網友回復:
多載寫一個 cout 物件的<<運算子就行了吧.不過在里面也是得要強制變換成現有的<<運算子對弄的型別才行.
cout是32位年代的產品, 對int64的支持可能不太好, 換成long long應該也是64位的.
uj5u.com熱心網友回復:
cout<<(int)path(i, i)<<endl;對 ll 型別 無 '<<'
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/93961.html
標籤:網絡編程
上一篇:不明白公司為什么愿意花二十萬請一個還在學C語言的碩士應界
下一篇:mfc單檔案初始化問題
