hdu 5113 Black And White(DFS染色)

Problem - 5113 (hdu.edu.cn)

hdu没法提交,我以为我账号又崩了...

复制代码
#include<iostream>
#include<cstring>
using namespace std;
int T,n,m,k,kase;
int color[30],ans[10][10];
bool DFS(int x,int y,int cur){
    if(x>n) return true;
    for(int i=1;i<=k;i++){
        if(!color[i] || ans[x-1][y]==i || ans[x][y-1]==i) continue;
        color[i]--;
        ans[x][y]=i;
        if(y<m && DFS(x,y+1,cur+1)) return true;
        else if(y==m && DFS(x+1,1,cur+1))  return true;
        color[i]++;
    }
    return false;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>T;
    while(T--){
        cin>>n>>m>>k;
        for(int i=1;i<=k;i++) cin>>color[i];
        cout<<"Case #"<<++kase<<":"<<endl;
        if(DFS(1,1,1)){
            cout<<"YES"<<endl;
            for(int i=1;i<=n;i++){
                cout<<ans[i][1];
                for(int j=2;j<=m;j++) cout<<" "<<ans[i][j];
                cout<<endl;
            }
        }else cout<<"NO"<<endl;
    }
    return 0;
}
复制代码

 

posted @   ACCbulb  阅读(4)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示