UVALIVE 2955 Vivian's Problem
参考: 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的更多相关文章
- UVALive 7457 Discrete Logarithm Problem (暴力枚举)
Discrete Logarithm Problem 题目链接: http://acm.hust.edu.cn/vjudge/contest/127401#problem/D Description ...
- 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 ...
- UVALive 6909 Kevin's Problem 数学排列组合
Kevin's Problem 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid ...
- UVALive - 7041 G - The Problem to Slow Down You
题意:求两个串的公共回文子串个数 题解:建两个回文自动机,从0和1各跑一边就是答案了,因为对于回文自动机来说,从头开始dfs就能找出该字符串的所有回文串 //#pragma GCC optimize( ...
- Vivian's Problem UVA - 1323(梅林素数+状压二进制)
借鉴:https://blog.csdn.net/miku23736748/article/details/52135932 https://blog.csdn.net/acm_cxlove/arti ...
- [UVALive 3683] A Scheduling Problem
图片加载可能有点慢,请跳过题面先看题解,谢谢 题目给出了一个信息:答案是有向边最长路 \(k\) 的值或者是 \(k+1\) 的值 那么题目就变成了:求是否有一种给无向边定向的方案,使得在以有向边最长 ...
- 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 ...
- UVaLive 7457 Discrete Logarithm Problem (暴力)
题意:求一个x使得 a^x%p = b p为素数: 析:从1开始扫一下就好,扫到p-1就可以了,关键是这个题为什么要用文件尾结束,明明说是0,但是不写就WA... 代码如下: #pragma comm ...
- UVALive 7037:The Problem Needs 3D Arrays(最大密度子图)
题目链接 题意 给出n个点,每个点有一个值,现在要选择一些点的集合,使得(选择的点生成的逆序对数目)/(选择的点的数量)的比率最大. 思路 点与点之间生成一个逆序对可以看做是得到一个边,那么就是分数规 ...
随机推荐
- POJ:3276-Face The Right Way(线性反转)
Face The Right Way Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6259 Accepted: 2898 De ...
- Java Spring Controller 获取请求参数的几种方法
技术交流群:233513714 1.直接把表单的参数写在Controller相应的方法的形参中,适用于get方式提交,不适用于post方式提交.若"Content-Type"=& ...
- luogu2221 [HAOI2012]高速公路
和sdoi的相关分析很像qwq,推柿子然后线段树搞搞 #include <iostream> #include <cstdio> using namespace std; ty ...
- 掌握OpenStack部署的最佳实践 打破部署失败的魔咒
部署OpenStack环境并不是一项简单的任务:根据SUSE最近的调查显示“曾经部署过OpenStack的企业当中有一半都失败了”.然而,随着最佳实践的出现,企业可以使用其避免在部署OpenStack ...
- 《数据结构与算法分析:C语言描述》复习——第八章“并查集”——并查集
2014.06.18 14:16 简介: “并查集”,英文名为“union-find set”,从名字就能看出来它支持合并与查找功能.另外还有一个名字叫“disjoint set”,中文名叫不相交集合 ...
- 《Cracking the Coding Interview》——第6章:智力题——题目2
2014-03-19 06:57 题目:对于8x8的棋盘,如果拿掉对角位置的两个小块儿,能否用1x2的多米诺牌拼成剩下的棋盘? 解法:不可能.且不说8x8,NxN都是不可能的.如果N是奇数,NxN-2 ...
- IOS测试,打不开要测试的APP怎么办?设置信任
步骤:设置-->通用-->设备管理-->企业级应用-->信任 具体教程:http://jingyan.baidu.com/article/ab69b27085ab002ca71 ...
- python 学习分享-paramiko模块
paramiko模块学习分享 paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接.paramiko支持Linux, Solaris, BS ...
- codeblocks17.12 debug 报错:ERROR: You need to specify a debugger program in the debuggers's settings.
DebugERROR: You need to specify a debugger program in the debuggers's settings.(For MinGW compilers, ...
- Elasticsearch相关度评分_score
相关度评分 _score 的目的 是为了将当前查询的结果进行排序,比较不同查询结果的相关度评分没有太大意义. _score的计算方式 score(q,d) = # score(q,d) 是文档 d 与 ...