参考: http://blog.csdn.net/acm_cxlove/article/details/7860735

感觉这里需要记录一下

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
int mason[] = {,,,,,,,};
int cnt[] = {,,,,,,,};
bool dp[<<];
int K,src[];
int trans(int x)
{
int ans = ;
for (int i = ; i < ; i++)
{
if (x % mason[i] == )
{
x /= mason[i];
if (x % mason[i] == ) return ;
ans |= (<<i);
}
}
if (x != ) return ;
return ans;
}
int calcu(int sta)
{
int ans = ;
for (int i = ; i < ; i++)
if (sta & (<<i))
ans += cnt[i];
return ans;
}
int main()
{
while (scanf("%d",&K)!=EOF)
{
//if (K == 0) break;
int cnt = ;
for (int i = ; i < K; i++)
{
scanf("%d",&src[i]);
src[i] = trans(src[i]);
if (src[i] == ) cnt++;
}
if (cnt == K) { puts("NO"); continue; }
memset(dp,false,sizeof(dp));
dp[] = true;
for (int i = ; i < K; i++)
for (int j = ; j < (<<); j++)
{
if (!(src[i] & j))
if (dp[j]) dp[j|src[i]] = true;
}
int ans = ;
for (int i = ; i < (<<); i++)
if (dp[i])
ans = max(ans,calcu(i));
printf("%d\n",ans);
}
return ;
}

UVALIVE 2955 Vivian's Problem的更多相关文章

  1. UVALive 7457 Discrete Logarithm Problem (暴力枚举)

    Discrete Logarithm Problem 题目链接: http://acm.hust.edu.cn/vjudge/contest/127401#problem/D Description ...

  2. Gym 101194A / UVALive 7897 - Number Theory Problem - [找规律水题][2016 EC-Final Problem A]

    题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...

  3. UVALive 6909 Kevin's Problem 数学排列组合

    Kevin's Problem 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid ...

  4. UVALive - 7041 G - The Problem to Slow Down You

    题意:求两个串的公共回文子串个数 题解:建两个回文自动机,从0和1各跑一边就是答案了,因为对于回文自动机来说,从头开始dfs就能找出该字符串的所有回文串 //#pragma GCC optimize( ...

  5. Vivian's Problem UVA - 1323(梅林素数+状压二进制)

    借鉴:https://blog.csdn.net/miku23736748/article/details/52135932 https://blog.csdn.net/acm_cxlove/arti ...

  6. [UVALive 3683] A Scheduling Problem

    图片加载可能有点慢,请跳过题面先看题解,谢谢 题目给出了一个信息:答案是有向边最长路 \(k\) 的值或者是 \(k+1\) 的值 那么题目就变成了:求是否有一种给无向边定向的方案,使得在以有向边最长 ...

  7. UVALive - 3521 Joseph's Problem (整除分块)

    给定$n,k$$(1\leqslant n,k\leqslant 10^9)$,计算$\sum\limits _{i=1}^nk\: mod\:i$ 通过观察易发现$k\%i=k-\left \lfl ...

  8. UVaLive 7457 Discrete Logarithm Problem (暴力)

    题意:求一个x使得 a^x%p = b p为素数: 析:从1开始扫一下就好,扫到p-1就可以了,关键是这个题为什么要用文件尾结束,明明说是0,但是不写就WA... 代码如下: #pragma comm ...

  9. UVALive 7037:The Problem Needs 3D Arrays(最大密度子图)

    题目链接 题意 给出n个点,每个点有一个值,现在要选择一些点的集合,使得(选择的点生成的逆序对数目)/(选择的点的数量)的比率最大. 思路 点与点之间生成一个逆序对可以看做是得到一个边,那么就是分数规 ...

随机推荐

  1. SpringMVC使用注解@RequestMapping映射请求

    pringMVC通过使用@RequestMapping注解,实现指定控制器可以处理哪些URL请求. 控制器的类定义及方法定义处都可以标注@RequestMapping: 类定义处:提供初步的请求映射信 ...

  2. [CodeForces948C]Producing Snow(优先队列)

    Description 题目链接 Solution 将温度做一个前缀和,用一个优先队列依次处理一遍 思路还是很简单的 Code #include <cstdio> #include < ...

  3. python-8错误调试测试

    1-错误处理 import logging try: print('try.......') r = 10/0 except ValueError as e: print('result:', e) ...

  4. Eclipse字体修改

    第一步: 第二步: 第三步: 第四步: 第五步: 第六步:

  5. Python locale 多语言模块和我遇到的坑

    Table of Contents 1. locale遇到的问题 1.1. locale 简介 1.1.1. 什么是locale 1.1.2. locale 相关命令 1.2. Python loca ...

  6. 11,flask之--WTForms

    WTForms是什么? 相当于django的ModelForm. 在网页中,为了和用户进行信息交互总是不得不出现一些表单.flask设计了WTForm表单库来使flask可以更加简便地管理操作表单数据 ...

  7. easyui-datagrid单选模式下隐藏表头的全选框

    easyui-datagrid可以不使用复选框来进行单选,直接使用onSelect和 singleSelect:true就可以实现单选,但是有一些用户会比较习惯使用勾选框,这时会加一列checkbox ...

  8. HTML简易学习笔记

    文字版地址 https://github.com/songzhenhua/github/blob/master/HTML简易学习笔记.txt

  9. Ironic-Python-Agent

    Ironic-Python-Agent 在PXE部署环境中,deploy模块是通过打开一个iSCSI设备,ironic-conductro将OS的镜像文件写到iSCSI的设备,所以deploy_ram ...

  10. hnust 分蛋糕

    问题 B: 分蛋糕 时间限制: 1 Sec  内存限制: 128 MB提交: 2430  解决: 966[提交][状态][讨论版] 题目描述 今天是DK生日,由于DK的朋友很多,所以DK在蛋糕店定制了 ...