Sicily 1155. Can I Post the lette
生活随笔
收集整理的這篇文章主要介紹了
Sicily 1155. Can I Post the lette
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include<iostream>
#include<memory.h>
using namespace std;
bool a[200];//標記是否走過
int b[200][200];
int n,m;
bool flag;
void dfs(int start,int count)
{if(start==n-1){flag=true;return;}else if(start==n){flag=false;return;}else{for(int i=0;i<n;i++){if(b[start][i]==0&&!a[i]){dfs(i,count+1);a[i]=1;}} }}
int main(int argc, char **argv)
{while(cin>>n&&n!=0){cin>>m;memset(a,false,sizeof(a));memset(b,-1,sizeof(b));int p,q;for(int i=0;i<m;i++){cin>>p>>q;b[p][q]=0;}flag=false;dfs(0,0);if(flag){cout<<"I can post the letter"<<endl;}else{cout<<"I can't post the letter"<<endl;}} return 0;}
思路:深度搜索每個城市是否存在道路,并用一個數組保存訪問記錄,識別能不能到達終點。
轉載于:https://www.cnblogs.com/xlqtlhx/p/7554759.html
總結
以上是生活随笔為你收集整理的Sicily 1155. Can I Post the lette的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 技术派的梦想旅行 用大数据推动旅游2.0
- 下一篇: 免费申请Firefly-RK3288开源