I NEED A OFFER!

本文介绍了一个经典的背包问题案例,通过代码实现展示了如何使用动态规划解决背包问题。文章提供了完整的C++代码示例,并解释了核心思路及算法流程。

题目地址

思路:背包的入门题

背包讲解

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#define ll long long
using namespace std;

const int maxn = 1e4 + 5;
int n, m, feiyong[maxn];
double jilv[maxn], dp[maxn];

int main()
{
    while(scanf("%d%d", &n, &m) != EOF && (n || m))
    {
          for(int i = 0; i < m; i++)
          {
                scanf("%d%lf", &feiyong[i], &jilv[i]);
                jilv[i] = 1 - jilv[i];
          }
          for(int i = 0; i <= n; i++)
          {
                dp[i] = 1.0;
          }
          for(int i = 0; i < m; i++)
          {
                for(int j = n;j >= feiyong[i]; j--)
                {
                      dp[j] = min(dp[j], dp[j-feiyong[i]]*jilv[i]);
                }
          }
          double out = (1 - dp[n]) * 100;
          printf("%.1lf%%\n", out);
    }

    return 0;
}


Dear Friend ; Especially for you - this amazing announcement . This is a one time mailing there is no need to request removal if you won't want any more ! This mail is being sent in compliance with Senate bill 2316 , Title 1 ; Section 303 ! This is not a get rich scheme . Why work for somebody else when you can become rich in 77 months . Have you ever noticed society seems to be moving faster and faster and more people than ever are surfing the web ! Well, now is your chance to capitalize on this ! We will help you turn your business into an E-BUSINESS and sell more . You can begin at absolutely no cost to you . But don't believe us . Ms Ames who resides in Indiana tried us and says "Now I'm rich, Rich, RICH" . We are licensed to operate in all states . If not for you then for your LOVED ONES - act now ! Sign up a friend and you'll get a discount of 30% ! Thank-you for your serious consideration of our offer . Dear Colleague ; Your email address has been submitted to us indicating your interest in our letter ! This is a one time mailing there is no need to request removal if you won't want any more ! This mail is being sent in compliance with Senate bill 2516 ; Title 1 , Section 304 . This is not a get rich scheme ! Why work for somebody else when you can become rich inside 34 months ! Have you ever noticed how long the line-ups are at bank machines plus people will do almost anything to avoid mailing their bills ! Well, now is your chance to capitalize on this ! We will help you process your orders within seconds and deliver goods right to the customer's doorstep ! You are guaranteed to succeed because we take all the risk ! But don't believe us . Mr Simpson of Oregon tried us and says "I've been poor and I've been rich - rich is better" . We are licensed to operate in all states . We urge you to contact us today for your own future financial well-being . Sign up a friend and you get half off . Thank-you for your serious consideration of our offer . Dear Salaryman ; Your email address has been submitted to us indicating your interest in our briefing . This is a one time mailing there is no need to request removal if you won't want any more ! This mail is being sent in compliance with Senate bill 1625 , Title 8 , Section 301 ! This is different than anything else you've seen ! Why work for somebody else when you can become rich in 38 weeks . Have you ever noticed how many people you know are on the Internet and nearly every commercial on television has a .com on in it ! Well, now is your chance to capitalize on this ! WE will help YOU deliver goods right to the customer's doorstep plus increase customer response by 160% ! You can begin at absolutely no cost to you . But don't believe us ! Prof Simpson who resides in Idaho tried us and says "I was skeptical but it worked for me" ! We are licensed to operate in all states ! We IMPLORE you - act now . Sign up a friend and you'll get a discount of 30% . Thanks . 找出flag
最新发布
05-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值