zoukankan      html  css  js  c++  java
  • POJ 1837 Balance 水题, DP 难度:0

    题目

    http://poj.org/problem?id=1837


    题意

    单组数据,有一根杠杆,有R个钩子,其位置hi为整数且属于[-15,15],有C个重物,其质量wi为整数且属于[1,25],重物与重物之间,钩子与钩子之间彼此不同。忽略杠杆及重心的影响,有多少种方式使得全部重物都挂上钩子(某些钩子可能挂若干个重物)后杠杆平衡?

    思路

    由于状态比较小,即使n的五次方也足以承受,而且任意时刻杠杆的状态在[-15 * 25 * 20, 15 * 25 * 20]之间,所以可以直接穷举状态。

    感想

    代码

    #include <iostream>
    #include <cstdio>
    #include <assert.h>
    #include <map>
    #include <cstring>
    
    using namespace std;
    
    const int maxc = 15;
    const int maxg = 25;
    const int cnum = 20;
    const int gnum = 20;
    
    const int base = maxc * maxg * cnum;
    const int maxsta = base * 2 + 1;
    
    int h[maxc];
    int w[maxg];
    int a[maxg + 1][maxsta];
    
    
    int main() {
        int c, g;
        cin>>c>>g;
        for(int i = 0; i < c; i++) {
            cin>>h[i];
        }
        for(int i = 0; i < g; i++) {
            cin>>w[i];
        }
        a[0][base] = 1;
        for(int i = 0;i < g;i++){
            for(int j = 0; j < maxsta;j++){
                if(a[i][j] == 0)continue;
                for(int k = 0;k < c;k++){
                    //cout<<i + 1<<" " <<j + w[i] * h[k] - base<<a[i][j]<<endl;
                    a[i + 1][j + w[i] * h[k]] += a[i][j];
                }
            }
        }
        cout<<a[g][base]<<endl;
        return 0;
    }
    
  • 相关阅读:
    201621123028《Java程序设计》第二周学习总结
    tensorflow——乘法
    最近做的事儿
    BlurUse Compute Shader
    又翻出来老电视剧看了看....
    exercise: toon shader
    semantic SV_
    SimpleDateFormat使用详解
    各种数字类型转换成字符串型:
    android 代码混淆配置
  • 原文地址:https://www.cnblogs.com/xuesu/p/6631199.html
Copyright © 2011-2022 走看看