ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

BZOJ 1433 ZJOI 2009 ¼ÙÆÚµÄËÞÉá ×î´óÁ÷ Dinic
2015-07-20 17:34:35 À´Ô´: ×÷Õß: ¡¾´ó ÖРС¡¿ ä¯ÀÀ:1´Î
Tags£ºBZOJ 1433 ZJOI 2009 ¼ÙÆÚ ËÞÉá ×î´ó Dinic

ÌâÄ¿´óÒ⣺һ¸öסУµÄÎÊÌ⣬¸ø³öÄÇЩÈËסУ£¬ÄÇЩÈ˲»×¡Ð££¬ÄÇЩÈ˺ÍÄÇЩÈËÈÏʶ£¬ÈÏʶµÄÈË¿ÉÒÔË­ËûµÄ´²£¬ÎÊÄܲ»ÄÜÂú×ãËùÓÐÈ˶¼Óд²×¡¡£


˼·£º¶þ·Öͼ×î´óÆ¥Å䣬µ±È»Ò²¿ÉÒÔÓÃÍøÂçÁ÷À´×ö¡£½¨Í¼·½·¨ÈçÏ£º

1.סУµÄÈËÏòTÁ¬±ß

2.Ïë˯µÄÈË´ÓSÁ¬±ß

3.»¥ÏàÈÏʶµÄÈËÁ¬±ß

È»ºóÅÜ×î´óÁ÷£¬ÅжÏÊÇ·ñÂúÁ÷£¬Êä³ö½á¹û¡£


CODE£º


#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        #define MAX 110 #define S 0 #define T (points << 1|1) #define INF 0x3f3f3f3f using namespace std; int cases,points; int map[MAX][MAX]; int have_bed[MAX]; int deep[MAX]; bool BFS(); int Dinic(int x,int flow); int main() { for(cin >> cases;cases; --cases) { scanf("%d",&points); int cnt = 0; memset(map,0,sizeof(map)); for(int i = 1;i <= points; ++i) { scanf("%d",&have_bed[i]); if(have_bed[i]) map[i + points][T] = 1; } for(int x,i = 1;i <= points; ++i) { scanf("%d",&x); if(!have_bed[i] || (have_bed[i] && !x)) map[S][i] = 1,cnt++; } for(int i = 1;i <= points; ++i) for(int x,j = 1;j <= points; ++j) { scanf("%d",&x); if(x || i == j) map[i][j + points] = 1; } int ans = 0; while(BFS()) ans += Dinic(S,INF); if(ans == cnt) puts("^_^"); else puts("T_T"); } return 0; } bool BFS() { static queue
       
         q; while(!q.empty()) q.pop(); memset(deep,0,sizeof(deep)); deep[S] = 1; q.push(S); while(!q.empty()) { int x = q.front(); q.pop(); for(int i = S;i <= T; ++i) if(map[x][i] && !deep[i]) { deep[i] = deep[x] + 1; q.push(i); if(i == T) return true; } } return false; } int Dinic(int x,int flow) { if(x == T) return flow; int temp = flow; for(int i = S;i <= T; ++i) if(deep[i] == deep[x] + 1 && map[x][i] && temp) { int away = Dinic(i,min(temp,map[x][i])); if(!away) deep[i] = 0; map[x][i] -= away; map[i][x] += away; temp -= away; } return flow - temp; }
       
      
     
    
   
  


¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
·ÖÏíµ½: 
ÉÏһƪ£ºhdu 1364 Illusive Chase (dfs) ÏÂһƪ£ºpoj 1185 ÅÚ±øÕóµØ £¨×´Ì¬Ñ¹ËõDP£©

ÆÀÂÛ

ÕÊ¡¡¡¡ºÅ: ÃÜÂë: (ÐÂÓû§×¢²á)
Ñé Ö¤ Âë:
±í¡¡¡¡Çé:
ÄÚ¡¡¡¡ÈÝ:

¡¤Linuxϵͳ¼ò½é (2025-12-25 21:55:25)
¡¤Linux°²×°MySQL¹ý³Ì (2025-12-25 21:55:22)
¡¤Linuxϵͳ°²×°½Ì³Ì£¨ (2025-12-25 21:55:20)
¡¤HTTP Åc HTTPS µÄ²î„ (2025-12-25 21:19:45)
¡¤ÍøÕ¾°²È«±ØÐ޿ΣºÍ¼ (2025-12-25 21:19:42)