题意:每组数据给出n个数,每个数在1-100,问组成这些数的蜡烛的权值的最小值。权值=把选的蜡烛从大到小排列组成的数

组成方式:比如有1 3两个蜡烛 可以组成13(1和3)或4(1+3) 只有一个加号可以用

解:位运算记录状态,can[i][j]表示在i的二进制所记录的状态下能不能组成j

can直接预处理出来,分类讨论 用一个数表示 还是用两个数表示 check的时候都在100以内 直接枚举

 #include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring> using namespace std; int n;
bool can[][];
int a[];
int cas=; bool check1(int x,int y,int z){
int cnt[];
memset(cnt,,sizeof(cnt));
int tmp=y;
while (tmp!=){
int now=tmp%;
tmp=tmp/;
if (((x&(<<now))==)||(cnt[now]>)) return false;
cnt[now]++;
}
tmp=z;
while (tmp!=){
int now=tmp%;
tmp=tmp/;
if (((x&(<<now))==)||(cnt[now]>)) return false;
cnt[now]++;
}
return true;
} bool check(int x,int y){
if ((y<)&&(x&(<<y))) return true;
for (int i=;i<=y/;i++){
if (i!=(y-i)){
if (check1(x,i,y-i)) return true;
}
}
if (y==) return false;
int tmpy1=y/;
int tmpy2=y%;
if (tmpy1==tmpy2) return false;
if ((x&(<<tmpy1))==) return false;
if ((x&(<<tmpy2))==) return false;
return true;
} int main(){
memset(can,,sizeof(can));
for (int i=;i<;i++){
for (int j=;j<=;j++) can[i][j]=check(i,j);
}
while (){
scanf("%d",&n);
if (n==) return ;
cas++;
bool flag;
int ans=;
for (int i=;i<=n;i++) scanf("%d",&a[i]);
for (int i=;i<;i++){
flag=true;
for (int j=;j<=n;j++) if (!can[i][a[j]]) flag=false;
if (flag){
int tmp=;
for (int j=;j>=;j--) if (i&(<<j)) tmp=tmp*+j;
if ((ans==)||(ans>tmp)) ans=tmp;
}
}
printf("Case %d: %d\n",cas,ans);
}
return ;
}
/*
2 10 11
1 30
0
*/
  

uvalive5810 uva12368 Candles的更多相关文章

  1. C - New Year Candles

    Problem description Vasily the Programmer loves romance, so this year he decided to illuminate his r ...

  2. codeforces A. New Year Candles 解题报告

    题目链接:http://codeforces.com/problemset/problem/379/A 题目意思:给定a支蜡烛(每支蜡烛可以燃烧1小时),可以在燃尽的a支蜡烛中看能组成多少组b支蜡烛, ...

  3. ARC 101 C - Candles

    题面在这里! 显然直接枚举左端点(右端点)就OK啦. #include<cstdio> #include<cstdlib> #include<algorithm> ...

  4. Gym - 101635K:Blowing Candles (简单旋转卡壳,求凸包宽度)

    题意:给定N个点,用矩形将所有点覆盖,要求矩形宽度最小. 思路:裸体,旋转卡壳去rotate即可. 最远距离是点到点:宽度是点到边. #include<bits/stdc++.h> #de ...

  5. Gym101635K Blowing Candles

    题目链接:http://codeforces.com/gym/101635 题目大意: 推荐一篇文章:https://blog.csdn.net/wang_heng199/article/detail ...

  6. Solution -「ABC 219H」Candles

    \(\mathcal{Description}\)   Link.   有 \(n\) 支蜡烛,第 \(i\) 支的坐标为 \(x_i\),初始长度为 \(a_i\),每单位时间燃烧变短 \(1\) ...

  7. Inverted sentences

    And ever has it been that love knows not its own depth until the hour of separation.  除非临到了别离的时候,爱永远 ...

  8. Good Bye 2013 A

    A. New Year Candles time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. HDU 5768:Lucky7(中国剩余定理 + 容斥原理)

    http://acm.hdu.edu.cn/showproblem.php?pid=5768 Lucky7 Problem Description   When ?? was born, seven ...

随机推荐

  1. 【原】从一个bug浅谈YUI3组件的资源加载

    篇前声明:为了不涉及业务细节,篇内信息统一以某游戏,某功能代替 前不久,某游戏准备内测客户端,开发人员测试过程中发现某功能突然不灵了,之前的测试一切ok,没有发现任何异常,第一反应是,游戏内浏览器都是 ...

  2. 离线使用nuget

    先新建一个项目,将所有想保存下来或者要升级的package先安装或升级. 然后在项目中将packages文件夹全部拷贝出来,专门放到一个目录备用,以后的项目就可以根据此packages文件夹来离线使用 ...

  3. Flex中如何通过showAllDataTips属性使鼠标移动到图表时显示所有的数据Tips的例子

    原文 http://blog.minidx.com/2008/11/10/1616.html 接下来的例子演示了Flex中如何通过showAllDataTips属性,使鼠标移动到图表时显示所有的数据T ...

  4. layerX offsetX pageX

    offsetX/offsetY:相对于当前元素的位移x/y:相对于当前座标系的位移,但是IE常常搞错当前座标系layerX/layerY:相对于当前座标系的位移pageX/pageY:相对于网页的位移 ...

  5. Linux中service命令和/etc/init.d/的关系

    Linux中service命令和/etc/init.d/的关系   service xxx启动 /etc/init.d/ 目录下的xxx脚本 如一个脚本名为 mysvc保存在/etc/init.d/下 ...

  6. 探究android控件及布局

    控件(widget) 1. TextView(该控件的一些需要注意的属性,下同) gravity="center"textSize="24sp"textColo ...

  7. [amazonaccess 1]logistic.py 特征提取

    ---恢复内容开始--- 本文件对应logistic.py amazonaccess介绍: 根据入职员工的定位(员工角色代码.角色所属家族代码等特征)判断员工是否有访问某资源的权限 logistic. ...

  8. #include <assert.h>

    assert宏 适用于软件测试.调试.排错 被除数不能为0,assert可以用于检测被除数是否为0 #define _CRT_SECURE_NO_WARNINGS //#define NDEBUG// ...

  9. hdu4740【杭州网赛、模拟、有点搜索?】

    当时看了这题就感觉so easy...  本来不想写的,后来感觉是不是可以练一下搜索水平.. 比赛时有人过了就没写.       比赛完了写一下. 实现还不是那么顺利,  囧 本来自己以为这题能练下搜 ...

  10. Swift中编写单例的正确方式

    在之前的帖子里聊过状态管理有多痛苦,有时这是不可避免的.一个状态管理的例子大家都很熟悉,那就是单例.使用Swift时,有许多方法实现单例,这是个麻烦事,因为我们不知道哪个最合适.这里我们来回顾一下单例 ...