| ||||||||||
| 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 | |||||||||
大家看看 我的代码为什么老是wa 附带一些跑过了的用例#include<iostream>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<cstring>
#include<stdio.h>
using namespace std;
int ma[17][10];
int d[10];
int row,col;
bool dfs(int from,int a[]){
int fl=0,fl2;
if(from>=row) return false;
for(int j=0;j<col;j+=32){
if(ma[from][j%32]!=0){
fl=1;break;
}
}
if(fl==0) return dfs(from+1,a);
int d2[10];
int iter,a2;
fl=0;
for(int i=0;i<10;i++){
d2[i]=a[i];
}
for(int j=0;j<col&&fl==0;j+=32){
for(int f=0;f<32&&f+j<col;f++){
if((1<<f)&ma[from][j/32]) {
if((1<<f)&d2[j/32])
{fl=1;break;}
}
}
d2[j/32]=d2[j/32]|ma[from][j/32];
}
if(fl){
return dfs(from+1,a);
}
else {
fl2=0;
for(int j=0;j<col&&fl2==0;j+=32){
for(int f=0;f<32&&f+j<col;f++){
if((d2[j%32]&(1<<f))==0) {
fl2=1;break;
}
}
}
if(fl2==0) return true;
if(dfs(from+1,d2)) return true;
}
return dfs(from+1,a);
}
int main(){
bool flag=true;
int num,t,pos;
while(cin>>row>>col){
memset(d,0,sizeof(d));
memset(ma,0,sizeof(ma));
for(int i=0;i<row;i++) {
num=0; pos=0;
for(int j=0;j<col;j+=32) {
num=0;
for(int k=0;k<32&&j+k<col;k++){
cin>>t;
num=(num<<1);
if(t==1) {
num|=1;
}
}
ma[i][pos]=num;
pos++;
}
}
flag=dfs(0,d);
if(flag) cout<<"Yes, I found it"<<endl;
else cout<<"It is impossible"<<endl;
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator