Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:谁给帮帮忙,看看代码哪里错了。感激不尽In Reply To:谁给帮帮忙,看看代码哪里错了。感激不尽 Posted by:tiankangwei at 2011-06-29 12:20:21 > > > #include <iostream> > using namespace std; > > bool col[10]; > char map[10][10]; > int n,k,res; > > void dfs( int r, int counter ) > { > if ( r >= n ) > return; > if ( counter == k ) > { > res++; > return; > } > for ( int i = 0; i < n; i++ ) > { > if ( map[r][i] == '#' && col[i] == 0 ) > { > col[i] = 1; > dfs(r+1,counter+1); > col[i] = 0; > } > } > dfs(r+1,counter); > } > > int main() > { > while ( cin >> n >> k && ! (n == -1 && k == -1) ) > { > getchar(); > memset(map,0,sizeof(map)); > memset(col,0,sizeof(col)); > for ( int i = 0; i < n; i++ ) > cin >> map[i]; > res = 0; > dfs(0,0); > cout << res << endl; > } > return 0; > } col[i] = 1; dfs(r+1,counter+1); col[i] = 0; 这里出问题了 改成 col[i] ++; dfs(r+1,counter+1); col[i] = --; 你仔细想想 可以看一下我写的8皇后问题 http://www.xinbaolianmeng.com/showshouye.aspx?type=7&ID=62 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator