BNUOJ 44583 Star Trek: First Contact

题意:自身有总能量a,敌方血量为b,有n枚导弹,发射时分别会消耗自身vi的能量,对对方造成wi的伤害,判断是否能用这些弹药摧毁敌舰

链接:http://www.bnuoj.com/v3/problem_show.php?pid=44583

思路:妥妥的裸背包问题,模板随便一搞就行

注意点:


以下为AC代码:

Username RunID ID Result Language Time Memory Length Submit Time
luminous11435469FAcceptedGNU C++4 ms1892 KB1389 B2014-12-26 20:09:20
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <list>
#include <cctype>
#include <algorithm>
#include <climits>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end()
#define clr(a, v) memset( a , v , sizeof(a) )
#define pb push_back
#define mp make_pair
#define read(f) freopen(f, "r", stdin)
#define write(f) freopen(f, "w", stdout)
using namespace std;

int w[105];
int v[105];
int dp[10005];

int main()
{
    ios::sync_with_stdio( false );
    int t;
    cin >> t;
    for ( int ncase = 1; ncase <= t; ncase ++ )
    {
        clr ( w, 0 );
        clr ( v, 0 );
        clr ( dp, 0 );
        int a, b, n;
        cin >> a >> b >> n;
        for ( int i = 0; i < n; i ++ )
        {
            cin >> v[i];
        }
        for ( int i = 0; i < n; i ++ )
        {
            cin >> w[i];
        }
        for ( int i = 0; i < n; i ++ )
        {
            for ( int j = a; j >= v[i]; j -- )
            {
                dp[j] = max ( dp[j], dp[j-v[i]] + w[i] );
            }
        }
        cout << "Case #"<< ncase <<": ";
        if ( dp[a] >= b )cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值