zoukankan      html  css  js  c++  java
  • 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 == 0 ? b : gcd(b, a % b);}
    int mason[] = {3,7,31,127,8191,131071,524287,2147483647};
    int cnt[] = {2,3,5,7,13,17,19,31};
    bool dp[1<<8];
    int K,src[110];
    int trans(int x)
    {
        int ans = 0;
        for (int i = 0; i < 8; i++)
        {
            if (x % mason[i] == 0)
            {
                x /= mason[i];
                if (x % mason[i] == 0) return 0;
                ans |= (1<<i);
            }
        }
        if (x != 1) return 0;
        return ans;
    }
    int calcu(int sta)
    {
        int ans = 0;
        for (int i = 0; i < 8; i++)
            if (sta & (1<<i))
                ans += cnt[i];
        return ans;
    }
    int main()
    {
        while (scanf("%d",&K)!=EOF)
        {
            //if (K == 0) break;
            int cnt = 0;
            for (int i = 0; i < K; i++)
            {
                scanf("%d",&src[i]);
                src[i] = trans(src[i]);
                if (src[i] == 0) cnt++;
            }
            if (cnt == K) { puts("NO"); continue; }
            memset(dp,false,sizeof(dp));
            dp[0] = true;
            for (int i = 0; i < K; i++)
                for (int j = 0; j < (1<<8); j++)
                {
                    if (!(src[i] & j))
                        if (dp[j]) dp[j|src[i]] = true;
                }
            int ans = 0;
            for (int i = 0; i < (1<<8); i++)
                if (dp[i])
                ans = max(ans,calcu(i));
            printf("%d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    c#多线程
    把.NET程序部署到没有安装.NET Framwork的机器上
    Java字符编码转换过程说明
    Window 消息大全使用详解
    Regsvr32
    VC++的应用程序框架中各类之间的访问方法
    java接收中文输入并正常显示
    Visual C#中的数据绑定
    截取系统 API 调用(转)
    几个操作文件的API函数
  • 原文地址:https://www.cnblogs.com/Commence/p/4004764.html
Copyright © 2011-2022 走看看