1002 Fire Net

來源:互聯網
上載者:User

標籤:style   blog   color   io   ar   for   sp   div   c   

用遞迴實現各種情況的枚舉,可以看做是考察DPS的簡單實現。

 1 #include <stdio.h> 2  3 int n,max,count,target[4][4]; 4  5 int place(int x,int y){ 6     int i; 7     for(i=y;i>=0;i--){ 8         if(target[x][i]>0) 9             return 0;10         if(target[x][i]<0)11             break;12     }13     for(i=y;i<n;i++){14         if(target[x][i]>0)15             return 0;16         if(target[x][i]<0)17             break;18     }19     for(i=x;i>=0;i--){20         if(target[i][y]>0)21             return 0;22         if(target[i][y]<0)23             break;24     }25     for(i=x;i<n;i++){26         if(target[i][y]>0)27             return 0;28         if(target[i][y]<0)29             break;30     }31     return 1;32 }33 34 void DFS(){35     int i,j;36     if(count>max)37         max=count;38     for(i=0;i<n;i++){39         for(j=0;j<n;j++){40             if(!target[i][j]&&place(i,j)){41                 target[i][j]=1;42                 count++;43                 DFS();44                 count--;45                 target[i][j]=0;46             }47         }48     }49 }50 51 int main(){52     int i,j;53     char c;54     while(1){55         scanf("%d",&n);56         if(n==0)57             break;58         max=count=0;59         for(i=0;i<n;i++){60             getchar();61             for(j=0;j<n;j++){62                 scanf("%c",&c);63                 target[i][j]=(c==‘X‘?-1:0);64             }65         }66         DFS();67         printf("%d\n",max);68     }69     return 0;70 }

 

1002 Fire Net

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.