"Algorithm Series learning" [Kuangbin you fly] topic 12 basic DP1 F-piggy-bank "complete knapsack problem"

Source: Internet
Author: User

Https://vjudge.net/contest/68966#problem/F

http://blog.csdn.net/libin56842/article/details/9048173

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <string>5#include <algorithm>6#include <cmath>7 #defineINF 0x3f3f3f3f8 using namespacestd;9 Const intmaxn=1e4+Ten;Ten intDP[MAXN]; One intweight[505]; A intmoney[505]; - intMain () - { the     intT; -scanf"%d",&T); -      while(t--) -     { +     //memset (Dp,0,sizeof (DP)); -         inte,f; +scanf"%d%d",&e,&F); A         intv=f-E; at          for(intI=0; i<=v;i++) -         { -dp[i]=INF; -         } -dp[0]=0; -         intN; inscanf"%d",&n); -          for(intI=1; i<=n;i++) to         { +scanf"%d%d",&money[i],&weight[i]); -         } the          for(intI=1; i<=n;i++) *         { $              for(intk=weight[i];k<=v;k++)Panax Notoginseng             { -Dp[k]=min (dp[k],dp[k-weight[i]]+money[i]); the             } +         } A         if(dp[v]<INF) the         { +printf"The minimum amount of money in the Piggy-bank is%d.\n", Dp[v]); -         } $         Else $         { -printf"This is impossible.\n"); -         } the          -     }Wuyi     return 0;  the}
View Code

"Algorithm Series learning" [Kuangbin you fly] topic 12 basic DP1 F-piggy-bank "complete knapsack problem"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.