模拟

状态压缩 

uva 12368 - Candles   2011 - Dhaka

 1 #include<stdio.h>
2 #include<string.h>
3 #include<iostream>
4 #include<string>
5 #include<algorithm>
6 #include<math.h>
7 #include<map>
8 #include<queue>
9 using namespace std;
10 #define LL long long
11 #define nMAX (1<<10+10)
12 #define mMAX 110
13 int ar[25],n;
14 int f[nMAX];
15 bool vis[nMAX][mMAX];
16 struct node{
17 int a,b,num;
18 };
19 void init(){
20 int a[100]; node b[100];
21 for(int x=0;x<(1<<10);x++){
22 int cnta=0,cntb=0;
23 for(int i=0;i<10;i++) if(x&(1<<i)){
24 a[cnta++]=i; vis[x][i]=true;
25 }
26 for(int i=0;i<cnta;i++) for(int j=0;j<cnta;j++) if(i!=j) {
27 int num=a[i]*10+a[j];
28 b[cntb].a=i, b[cntb].b=j, b[cntb++].num=num;
29 vis[x][num]=true;
30 }
31 for(int i=0;i<cnta;i++) for(int j=0;j<cnta;j++) if(i!=j){
32 int num=a[i]+a[j];
33 if(num<=100) vis[x][num]=true;
34 }
35 for(int i=0;i<cnta;i++) for(int j=0;j<cntb;j++) if(i!=b[j].a&&i!=b[j].b){
36 int num=a[i]+b[j].num;
37 if(num<=100) vis[x][num]=true;
38 }
39 for(int i=0;i<cntb;i++) for(int j=0;j<cntb;j++)
40 if(b[i].a!=b[j].a&&b[i].a!=b[j].b
41 &&b[i].b!=b[j].a&&b[i].b!=b[j].b){
42 int num=b[i].num+b[j].num;
43 if(num<=100) vis[x][num]=true;
44 }
45 }
46 }
47 bool ok(int x){
48 for(int i=0;i<n;i++) if(!vis[x][ar[i]]) return false;
49 return true;
50 }
51 int number(int x){
52 int sum=0, p=1;
53 for(int i=0;i<10;i++) if((1<<i)&x) {
54 sum+=i*p; p*=10;
55 }
56 return sum;
57 }
58 int main(){
59 int T=1; init();
60 for(int i=0;i<(1<<10);i++)
61 for(int j=0;j<10;j++) if(i&(1<<j)) f[i]++;
62 f[nMAX-1]=111;
63
64 while(scanf("%d",&n)&&n){
65 for(int i=0;i<n;i++) scanf("%d",&ar[i]);
66 int k=0,ans=nMAX-1;
67 for(int i=0;i<(1<<10);i++) {
68 if(ok(i)&&f[ans]>=f[i]){
69 if(f[ans]==f[i]&&number(ans)>number(i)) ans=i;
70 else if(f[ans]!=f[i])ans=i;
71 }
72 }
73 printf("Case %d: %d\n",T++,number(ans));
74 }
75 }



转载于:https://www.cnblogs.com/louisnit/archive/2012/03/25/2417075.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/274934.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

qt ui指针和本类对象_您需要了解的有关UI设计的形状和对象的所有信息

qt ui指针和本类对象重点 (Top highlight)第1部分 (Part 1) So you’re thinking about becoming a UX/UI designer, but are afraid to start? Don’t worry. It’s easier than you think. You only need a solid foundation and a lot of dedication. I can’t help you wi…

移动端h5页面复制粘贴(兼容到ios9安卓4.0.0)

项目使用jquery框架纯h5复制粘贴解决了iscroll4阻止所有默认事件&#xff0c;长按无法弹出复制菜单项目需要写一个上拉加载页面&#xff0c;页面中的物流信息需要可复制粘贴&#xff0c;同时需要兼容到ios9和安卓4.0.0, 经过大量搜索&#xff0c;最终使用clipboard。代码如下 &…

2021 大前端技术回顾及未来展望

大家好&#xff0c;我是若川。持续组织了6个月源码共读活动&#xff0c;感兴趣的可以点此加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。历史面试系列2021 …

最近想读的书想做的事

越来越多了&#xff0c;但是总是还没开始&#xff0c;一天拿出一小时&#xff0c;周末拿出一上午。加油加油 2012/3/27 C标准库 C专家编程Expert C Programming Deep C Secrets CodeCraft编程匠艺&#xff1a;编写卓越的代码 代码之美 重看 编程珠玑 编程卓越之道 卷1 卷2 代码…

skysat重访周期_重访小恶梦

skysat重访周期You awaken with a start, the nightmare still fogging your mind with terror. Rain falls through cracks in the ceiling above you. The room is sparse, metallic, desolate. Searching the pockets of your yellow raincoat, you find only a cigarette l…

Python这些位运算的妙用,绝对让你大开眼界

位运算的性能大家想必是清楚的&#xff0c;效率绝对高。相信爱好源码的同学&#xff0c;在学习阅读源码的过程中会发现不少源码使用了位运算。但是为啥在实际编程过程中应用少呢&#xff1f;想必最大的原因&#xff0c;是较为难懂。不过&#xff0c;在面试的过程中&#xff0c;…

记一次 Vue2 迁移 Vue3 的实践总结

大家好&#xff0c;我是若川。持续组织了6个月源码共读活动&#xff0c;感兴趣的可以点此加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。历史面试系列一、V…

改错3-38

#include<iostream.h>class time{private:int hour,minute,second;public:void settime(int h,int m,int s) { hour(h>0&&h<24)?h:0; minute(m>0&&m<60)?m:0; second(s>0&&s<60)?s:0; }void sh…

魔兽怀旧网站模块下载_一个人的网站重新设计和怀旧

魔兽怀旧网站模块下载Despite how I look, I’m the kind kind of person that loves to play old video games. (Full disclosure: I look exactly like the kind of person that loves to play old video games).尽管我长得很帅&#xff0c;但我还是一个喜欢玩旧视频游戏的人…

华为架构师谈如何理解运用模块与微服务

模块化还是微服务&#xff1f; 我们的业务由一个大型应用转向微服务的时候&#xff0c;除了很好展示漂亮的PPT&#xff0c;提升KPI之外&#xff0c;实际操作时将整个业务切成微型服务似乎也不费吹灰之力。但这种方法真的是我们的最佳选择吗&#xff1f;确实&#xff0c;维护凌乱…

Node.js 可以和 Web 实现 HTTP 请求的跨平台兼容了!

大家好&#xff0c;我是若川。持续组织了6个月源码共读活动&#xff0c;感兴趣的可以点此加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。历史面试系列大家好…

zeplin加载 不出图片_为什么Zeplin不能解决您的所有问题

zeplin加载 不出图片Design handover involves communicating the visual styles and behaviours of your design so they can be translated into code.设计移交涉及传达设计的视觉样式和行为&#xff0c;以便可以将它们转换为代码。 Back in the Dark Ages of digital desig…

POJ 基础数学

数学 组合数学 POJ3252,poj1850,poj1019,poj1942 数论 poj2635, poj3292,poj1845,poj2115 计算方法&#xff08;二分&#xff09; poj3273,poj3258,poj1905,poj3122 组合数学 poj 3252 题意&#xff1a;如果一个数是round number&#xff0c;则它的二进制表示中&#xff…

使用uwsgi和gunicorn部署Django项目

https://uwsgi-docs.readthedocs.io/en/latest/Management.html https://uwsgi-docs.readthedocs.io/en/latest/Management.html 先了解下相关杀进程命令 ps -ef|grep uwsgi|grep -v grep|awk {print $2}|xargs kill -9//查看uwsgi相关接口 ps -ef|grep uwsgi #查看相关端口 ne…

推荐2022前端必看的新书 《Vue.js设计与实现》

大家好&#xff0c;我是若川。持续组织了6个月源码共读活动&#xff0c;感兴趣的可以点此加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。历史面试系列这本新…

汉堡菜单_汉堡菜单-可访问性和用户体验设计原则的挑战?

汉堡菜单重点 (Top highlight)I was recently designing a hamburger menu for a client and before I knew it, I had embarked on this journey where I was reading article after article about the accessibility issues which accompany a hamburger icon. Turns out, th…

Server2012R2 ADFS3.0 The same client browser session has made '6' requests in the last '13'seconds

本问题是在windows server2012R2系统ADFS3.0环境下遇到的&#xff0c;CRM2013部署ADFS后运行一段时间(大概有一两个月)后在IE浏览器中访问登陆界面点击登陆后就报以下错误 “Microsoft.IdentityServer.Web.InvalidRequestException: MSIS7042: The same client browser session…

(原创)RHEL/CentOS 5.x使用yum快速安装MySQL 5.5.x

PS&#xff1a;MySQL 5.5系列成为稳定版已经有一段时间了&#xff0c;但据我调查了解&#xff0c;在生产环境中还是以5.1系列为主。在国内的大公司里&#xff0c;只确定金山在使用5.5了。 公司的其中几台广告统计服务器&#xff0c;之前的运维直接用了自带安装的MySQL 5.0系列。…

又一个基于 Esbuild 的神器!esno

大家好&#xff0c;我是若川。持续组织了6个月源码共读活动&#xff0c;感兴趣的可以点此加我微信 ruochuan02 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。历史面试系列esno我…

c# ui 滚动 分页_UI备忘单:分页,无限滚动和“加载更多”按钮

c# ui 滚动 分页重点 (Top highlight)When you have a lot of content, you have to rely on one of these three patterns to load it. So, which is best? What will your users like? What do most platforms use? These are the questions we will explore today.当内容…