【AtCoder】ABC104 All Green

本文探讨了一种解决特定类型多重背包问题的方法,目的是找到完成指定分数所需最少的题目数量。文章详细介绍了问题背景、算法分析、代码实现,并通过实例演示了如何使用该方法解决问题。

题目

beta传送门

题目大意

AtCoder网站上,题目有 D D 种分值,分别是100,200,...100D,分值为 100i 100 i 的题目有 pi p i 道,如果你把分值为 100i 100 i 的题目全部做完,可以获得额外的 ci c i 分,高桥小朋友想要得到 G G 分,问他至少要做多少道题。(1D10 1pi100 1 ≤ p i ≤ 100 1ci106 1 ≤ c i ≤ 10 6 G100 G ≥ 100 ci c i G G 都是100的倍数,保证有解)

分析

带限制的多重背包?好像某人用这种方法过了……

如果没有 ci c i ,那就直接从分最高的题目开始切。
二进制枚举要切哪几种题,从 pi p i 大的开始切,算要切多少题,统计答案。

代码

#include<cstdio>
#include<algorithm>
using namespace std;

#define MAXN 10
#define INF 0x3f3f3f3f
int D,G;
int P[MAXN+5],C[MAXN+5];

int main(){
    scanf("%d%d",&D,&G);
    for(int i=1;i<=D;i++)
        scanf("%d%d",&P[i],&C[i]);
    int Max=(1<<D)-1,Ans=INF;
    for(int i=0;i<=Max;i++){
        int cnt=0,rest=G;
        for(int j=D;j>=1&&rest>0;j--)//从大到小
            if(i&(1<<(j-1))){
                int tmp=P[j]*j*100;
                if(tmp>=rest){//足够
                    cnt+=(rest+100*j-1)/(100*j);
                    rest=0;
                    break;
                }
                else{//不够
                    rest-=tmp+C[j];
                    cnt+=P[j];
                }
            }
        if(rest<=0)//分足够
            Ans=min(Ans,cnt);
    }
    printf("%d",Ans);
}
### AtCoder Contest ABC346 Problems and Information AtCoder Beginner Contest (ABC) 346 is a programming competition designed to challenge participants with various algorithmic problems. Each problem within the contest has specific constraints regarding time limits, memory usage, and expected outputs. For instance, one of the sample output formats provided shows how results should be structured when submitting solutions[^3]. The format typically includes multiple test cases where each case expects certain input parameters leading to predefined outcomes. In terms of difficulty levels, contests like these usually start from easier tasks labeled as A or B progressing towards more complex challenges marked by letters such as D or E. Participants are encouraged to solve all given questions but must adhere strictly to guidelines concerning code length restrictions not exceeding 16KB along with execution times capped at 1 second per task while ensuring that no more than 256MB RAM is utilized during processing phases. Regarding legal aspects related possibly indirectly through referencing court decisions on jurisdictional matters which might apply broadly across online platforms hosting coding competitions; however this particular citation does not directly pertain specifically here[^2]. #### Example Problem Description Consider an example problem statement similar in structure though not exact wording: Given a binary tree represented implicitly via array indices, determine whether it can be inverted so every left child becomes a right child and vice versa without altering node values themselves. This type of question would fall under graph theory concepts applied practically within competitive programming environments aimed primarily toward beginners yet still requiring solid understanding fundamental data structures including trees alongside bitwise operations potentially useful solving space-efficiently due limited resources specified earlier mentioned constraints[^1]. ```python def invert_tree(tree_arr): n = len(tree_arr) for i in range(n//2): opposite_index = ((i+1)*(-1))-1 if abs(opposite_index) <= n: temp = tree_arr[i] tree_arr[i] = tree_arr[opposite_index] tree_arr[opposite_index] = temp return tree_arr ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值