题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1231
题意:多重部分和的解法有几种。
代码:
#include <stdio.h>
#include <ctime>
#include <math.h>
#include <limits.h>
#include <complex>
#include <string>
#include <functional>
#include <iterator>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <bitset>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <iostream>
#include <ctime>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
using namespace std;
int n, k;
int val[110],num[110];
int dp[110][1100];
int main()
{
int t;
scanf("%d",&t);
for (int ca = 1; ca <= t; ca++)
{
scanf("%d%d",&n,&k);
for (int i = 0; i < n; i++)
scanf("%d",&val[i]);
for (int i = 0; i < n; i++)
scanf("%d", &num[i]);
memset(dp,0,sizeof(dp));
dp[0][0] = 1;
for (int i = 0; i < n; i++)
for (int j = 0; j <= k; j++)
for (int p = 0; p <= num[i] && p*val[i] <= j; p++)
dp[i + 1][j] = (dp[i + 1][j] + dp[i][j - p*val[i]]) % 100000007;
printf("Case %d: %d\n",ca,dp[n][k]);
}
return 0;
}
时间: 2024-10-14 21:00:03