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个点,每个点有一个值,现在要选择一些点的集合,使得(选择的点生成的逆序对数目)/(选择的点的数量)的比率最大. 思路 点与点之间生成一个逆序对可以看做是得到一个边,那么就是分数规 ...
随机推荐
- 13,发布CRM
发布CRM你将使用以下软件 nginx uWSGI CentOS7 CRM项目文件 virtualenv supervisor WSGI.uWSGI python web服务器开发使用WSGI协议(W ...
- P1182 数列分段Section II
P1182 数列分段Section II 题目描述 对于给定的一个长度为N的正整数数列A[i],现要将其分成M(M≤N)段,并要求每段连续,且每段和的最大值最小. 关于最大值最小: 例如一数列4 2 ...
- 接口&抽象类&继承&父类和子类
1.接口是什么? 接口可以理解为一个特殊的抽象类,是由全局常量和公共抽象方法组成的. 所以,如果,一个抽象类的方法都是抽象的,那么就可以通过接口的形式来表示. class 用于定义类 interfac ...
- 在sqlserver 中如何导出数据库表结构到excel表格中
先建空白excel--在数据库中的左侧找到该表, 选中需要导出的数据--Ctrl+C复制--打开记事本修改编码格式为Unicode-不自动换行保存--Ctrl+A--Ctrl+C,再打开excel-- ...
- USACO Section1.3 Prime Cryptarithm 解题报告
crypt1解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...
- python自动化运维篇
1-1 Python运维-课程简介及基础 1-2 Python运维-自动化运维脚本编写 2-1 Python自动化运维-Ansible教程-Ansible介绍 2-2 Python自动化运维-Ansi ...
- Python全栈 MySQL 数据库 (索引、数据导入、导出)
ParisGabriel 每天坚持手写 一天一篇 决定坚持几年 为了梦想为了信仰 开局一张图 表字段重命名(change) alter table 表名 ...
- lshw
https://linux.die.net/man/1/lshw lshw(Hardware Lister)是另外一个可以查看硬件信息的工具,不仅如此,它还可以用来做一些硬件的benchmark. 这 ...
- Kickstart配置文件解析
参考:https://www.douban.com/note/270359374/?type=likehttp://blog.51cto.com/molinux/548247http://debugo ...
- c语言版贪吃蛇小游戏
编译环境:windows 7 64位 编译工具:codeblocks 13.12 备注:未使用graphics.h 声明:个人原创,未经允许,禁止转载!!! 数据结构:双向链表 1.程序未使用grap ...