标签:
#include<cstdio> #include<cmath> #include<algorithm> #include<cstring> using namespace std; int n; bool can[1024][101]; int a[11]; int cas=0; bool check1(int x,int y,int z){ int cnt[11]; memset(cnt,0,sizeof(cnt)); int tmp=y; while (tmp!=0){ int now=tmp%10; tmp=tmp/10; if (((x&(1<<now))==0)||(cnt[now]>0)) return false; cnt[now]++; } tmp=z; while (tmp!=0){ int now=tmp%10; tmp=tmp/10; if (((x&(1<<now))==0)||(cnt[now]>0)) return false; cnt[now]++; } return true; } bool check(int x,int y){ if ((y<10)&&(x&(1<<y))) return true; for (int i=1;i<=y/2;i++){ if (i!=(y-i)){ if (check1(x,i,y-i)) return true; } } if (y==100) return false; int tmpy1=y/10; int tmpy2=y%10; if (tmpy1==tmpy2) return false; if ((x&(1<<tmpy1))==0) return false; if ((x&(1<<tmpy2))==0) return false; return true; } int main(){ memset(can,0,sizeof(can)); for (int i=1;i<1024;i++){ for (int j=1;j<=100;j++) can[i][j]=check(i,j); } while (1){ scanf("%d",&n); if (n==0) return 0; cas++; bool flag; int ans=0; for (int i=1;i<=n;i++) scanf("%d",&a[i]); for (int i=1;i<1024;i++){ flag=true; for (int j=1;j<=n;j++) if (!can[i][a[j]]) flag=false; if (flag){ int tmp=0; for (int j=9;j>=0;j--) if (i&(1<<j)) tmp=tmp*10+j; if ((ans==0)||(ans>tmp)) ans=tmp; } } printf("Case %d: %d\n",cas,ans); } return 0; } /* 2 10 11 1 30 0 */
标签:
原文地址:http://www.cnblogs.com/baby-mouse/p/4296298.html