# poj 1276 Cash Machine

//转来的代码

#include <iostream>

using namespace std;int a[15][2];int dp[120001];int value[1001];int main(){int cash, n;while (cin >> cash >> n){int i;int k = 0;for (i = 0; i < n; ++i){   cin >> a[i][0] >> a[i][1];int j = 1;while (j <= a[i][0]){    value[k++] = a[i][1] * j;    a[i][0] -= j;    j *= 2;}if (a[i][0] > 0)    value[k++] = a[i][1] * a[i][0];}memset(dp,0,sizeof(dp));for (i = 0; i < k; ++i)for (int j = cash; j >= 0; --j){if (j - value[i] >= 0)     dp[j] = dp[j] > dp[j-value[i]] + value[i] ? dp[j] : dp[j-value[i]] + value[i];}  cout << dp[cash] << endl;}return 0;}

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

struct node
{

int num;

int value;

}
a[15];

bool dp[100001];
int cash,N;

int main ()
{

int i,j,k;

while(scanf("%d%d",&cash,&N)!=EOF)

{

memset(dp,
0,sizeof(dp));

for(i=1;i<=N;i++)
scanf(
"%d%d",&a[i].num,&a[i].value);

if (cash==0||N==0)

{
printf(
"0/n");

continue;
}

int max=0;
dp[
0]=true;

for(i=1;i<=N;i++)

{

if(a[i].value>cash)

continue;

for(j=max;j>=0;j--)

{

if(dp[j]==true)

for(k=1;k<=a[i].num;k++)

{

{

int temp=j+k*a[i].value;

if(temp>cash)

break;

if(temp>max)

{
max
=temp;

}

dp[temp]
=true;
}

}

}

}

printf(
"%d/n",max);

}

return 0;
}

#### poj 1276 Cash Machine

2016-08-23 19:08:16

#### poj&nbsp;1276&nbsp;Cash&nbsp;Machine

2014-12-29 08:21:23

#### Poj 1276 Cash Machine

2014-11-24 22:02:03

#### POJ 1276--Cash Machine

2014-07-26 14:06:34

#### poj1276Cash Machine【多重背包模板题】

2016-05-11 17:00:53

#### POJ 1276 cash machine

2013-05-16 19:48:03

#### POJ 1276 Cash Machine

2013-09-04 20:11:54

#### poj 1276 Cash machine

2012-06-14 00:21:01

#### POJ 1276 Cash Machine

2015-08-09 15:24:41