标签:des blog http io ar os sp for strong
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 27989 | Accepted: 9986 | 
Description
Input
Output
Sample Input
735 3 4 125 6 5 3 350 633 4 500 30 6 100 1 5 0 1 735 0 0 3 10 100 10 50 10 10
Sample Output
735 630 0 0
Hint
Source
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<vector>
#include<set>
using namespace std;
#define maxn 100010 
int a[11],type[11],m[100001];
 
int main()
{
   int money,num,i,j,k;
    
       while(~scanf("%d%d",&money,&num))
       {
          for(i =0 ; i < num ; ++i)
          {
                scanf("%d%d",&a[i],&type[i]);                                 
                m[type[i]] = 1;
          }
           
          memset(m,0,sizeof(m));
          m[0] = 1;
           
          for(i = 0 ; i < num ; ++i)
          {
              for(j = money ; j >= 0 ; --j)      
              if(m[j])
              {
                  for(k = 1; k <= a[i]; ++k)
                  {
                      if(j + k*type[i] > money) break;
                      m[j+k*type[i]] = 1; 
                  } 
              }      
          } 
                                        
          for(i = money ; i >= 0 ; --i)
          if(m[i])
          {                    
            printf("%d\n",i);               
            break;
          } 
       }
   return 0; 
}
标签:des blog http io ar os sp for strong
原文地址:http://www.cnblogs.com/a972290869/p/4099507.html