参考: 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. Ubuntu 14.10 配置JDK + J2EE

    本文仅作为本人在Ubuntu 14.10下安装JDK + J2EE的一个记录: 安装JDK 从Oracle的官网下载jdk-7u75-linux-x64.tar.gz 将jdk-7u75-linux- ...

  2. UOJ #2321. 「清华集训 2017」无限之环

    首先裂点表示四个方向 一条边上都有插头或者都不有插头,相当于满足流量平衡 最大流 = 插头个数*2时有解 然后求最小费用最大流 黑白染色分别连原点汇点

  3. SpringBoot推荐基础包

    技术交流群:233513714 Spring Boot 推荐的基础包 名称 说明 spring-boot-starter 核心 POM,包含自动配置支持.日志库和对 YAML 配置文件的支持. spr ...

  4. ceph 存储系统

    http://w w w.c s d n 123.com/html/topnews201408/2/4702.htm

  5. 常见排序算法题(java版)

    常见排序算法题(java版) //插入排序:   package org.rut.util.algorithm.support;   import org.rut.util.algorithm.Sor ...

  6. 剑指Offer - 九度1366 - 栈的压入、弹出序列

    剑指Offer - 九度1366 - 栈的压入.弹出序列2014-02-05 20:41 题目描述: 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的所 ...

  7. 孤荷凌寒自学python第五十一天初次尝试使用python连接Firebase数据库

    孤荷凌寒自学python第五十一天初次尝试使用python连接Firebase数据库 (完整学习过程屏幕记录视频地址在文末) 今天继续研究Firebase数据库,利用google免费提供的这个数据库服 ...

  8. 简述Shiro验证过程

    如果让我们自己实现用户登录验证我们都需要哪些步骤? 很简单,根据用户提供的账号从数据库中查询该账户的密码以及一些其他信息,然后拿这个密码与用户输入的密码相比较,因为保存在数据库中的密码一般是经过加密的 ...

  9. matlab使用摄像头人脸识别

    #关于matlab如何读取图片.视频.摄像头设备数据# 参见:http://blog.csdn.net/u010177286/article/details/45646173 但是,关于摄像头读取,上 ...

  10. springbootday06 mysql

    一.MySql 1. 数据库概述 数据库( Database )是按照数据结构来组织.存储和管理数据的仓库 . 数据按照特定的格式存储起来,用户可以通过SQL (Structured Query La ...