2 3 1 2 1 2 3 5 0 3 0 3 0 3
2 12这道题还不错。。可以把每个水果的单价看成1,然后要求m个水果即为求价值为m的组合数#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <string> #include <cctype> #include <vector> #include <cstdio> #include <cmath> #include <deque> #include <stack> #include <map> #include <set> #define ll long long #define maxn 116 #define pp pair<int,int> #define INF 0x3f3f3f3f #define max(x,y) ( ((x) > (y)) ? (x) : (y) ) #define min(x,y) ( ((x) > (y)) ? (y) : (x) ) using namespace std; int n,m,a[maxn],b[maxn],num_low[maxn],num_up[maxn]; void solve() { memset(a,0,sizeof(a));a[0]=1; for(int i=0;i<n;i++) { memset(b,0,sizeof(b)); for(int j=num_low[i];j<=num_up[i]&&j<=m;j++) for(int k=0;k+j<=m;k++) b[k+j]+=a[k]; memcpy(a,b,sizeof(b)); } printf("%d\n",a[m]); } int main() { while(~scanf("%d%d",&n,&m)) { for(int i=0;i<n;i++) scanf("%d%d",num_low+i,num_up+i); solve(); } return 0; }
原文地址:http://blog.csdn.net/qq_16255321/article/details/41122197