zoukankan      html  css  js  c++  java
  • hdoj1171

    //用母函数来做

    #include
    <iostream>
    #include
    <stdio.h>
    #include
    <string.h>
    using namespace std;
    int N, M, V, B, Max;
    bool s1[250000];        //由于只要求知道存在与否,不要求数值,可以用bool型
    int main()
    {
        
    while (scanf("%d"&N) != EOF && N > -1) {
        memset(s1, 
    0sizeof(s1));    //初始化
        s1[0= 1;
        Max 
    = 0;
        
    for (int i = 0; i < N; ++i) {
            scanf(
    "%d%d"&V, &M);
            
    for (int j = 0; j <= M; ++j) {
            
    for (int k = 0; k <= Max / 2++k) {
                s1[k 
    + j * V] |= s1[k];    //与或,相当于'加'
            }
            }
            Max 
    += V * M;    //不断地增加最大数值
        }
        B 
    = Max / 2;
        
    while (!s1[B])        //只要能形成B,就一定能形成A(A=Max-B)
            B--;
        printf(
    "%d %d\n", Max - B, B);

        }
    }


  • 相关阅读:
    Centos7 安装配置Elasticsearch
    单例模式
    Eclipse上部署maven项目
    单点登录
    各eclipse插件的作用
    eclipse中安装Subclipse插件
    往idea中导入已有的web项目
    maven 项目部署
    【转帖】算法刷题网站
    混淆矩阵-MATLAB代码详解
  • 原文地址:https://www.cnblogs.com/Open_Source/p/1904963.html
Copyright © 2011-2022 走看看