zoukankan      html  css  js  c++  java
  • F

     1 // worfzyq
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <vector>
     5 #include <algorithm>
     6 #include <map>
     7 #include <string>
     8 #include <set>
     9 using namespace std;
    10 typedef long long LL;
    11 const int MAX = 1e5+10;
    12 const int MOD = 1e9+7;
    13 int dp[110][1<<16],has[110];
    14 int prime[15]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
    15 int a[MAX];
    16 void init() {
    17     memset(has,0,sizeof(has));
    18     for(int i=1;i<=100;i++) {
    19         for(int j=0;j<15;j++) {
    20             if(i%prime[j]==0) {
    21                 has[i]|=(1<<j);
    22             }
    23         }
    24     }
    25 }
    26 int main() {
    27     //freopen("in.txt","w",stdout);
    28     init();
    29     int n,x;
    30     while(scanf("%d %d",&n,&x)==2) {
    31         for(int i=0;i<n;i++) {
    32             scanf("%d",&a[i]);
    33         }
    34         memset(dp,0,sizeof(dp));
    35         for(int i=0;i<n;i++) {
    36             for(int j=0;j<(1<<15);j++) {
    37                 dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
    38                 if((j&has[a[i]])==0) {
    39                     dp[i+1][j|has[a[i]]]=max(dp[i+1][j|has[a[i]]],dp[i][j]+1);
    40                 }
    41             }
    42         }
    43         int ans=0;
    44         for(int i=0;i<(1<<15);i++) {
    45             ans=max(ans,dp[n][i]);
    46         }
    47         if(n&1) {
    48             if(ans>=n/2) {
    49                 if(x>=1) printf("YES ");
    50                 else printf("NO ");
    51             }
    52             else {
    53                 if(x>=n-ans*2) {
    54                     printf("YES ");
    55                 }
    56                 else {
    57                     printf("NO ");
    58                 }
    59             }
    60         }
    61         else {
    62             if(ans>=n/2) {
    63                 printf("YES ");
    64             }
    65             else {
    66                 if(x>=n-ans*2) {
    67                     printf("YES ");
    68                 }
    69                 else {
    70                     printf("NO ");
    71                 }
    72             }
    73         }
    74     }
    75     return 0;
    76 }
  • 相关阅读:
    Constants and Variables
    随想
    C#基础篇之语言和框架介绍
    Python基础19 实例方法 类方法 静态方法 私有变量 私有方法 属性
    Python基础18 实例变量 类变量 构造方法
    Python基础17 嵌套函数 函数类型和Lambda表达式 三大基础函数 filter() map() reduce()
    Python基础16 函数返回值 作用区域 生成器
    Python基础11 List插入,删除,替换和其他常用方法 insert() remove() pop() reverse() copy() clear() index() count()
    Python基础15 函数的定义 使用关键字参数调用 参数默认值 可变参数
    Python基础14 字典的创建修改访问和遍历 popitem() keys() values() items()
  • 原文地址:https://www.cnblogs.com/acvc/p/4303967.html
Copyright © 2011-2022 走看看