标签:
你来帮帮他吧。
(xhd觉得一样学分的课没差别)
2 2 2 1 2 2 1 40 8 1 1 2 2 3 2 4 2 5 8 6 9 7 6 8 8
2 445
简单母函数,懂得模板意思就能做了。
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#define N 100
using namespace std;
int c1[N],c2[N];
int T,n,k;
struct Node
{
int a,b;
}f[N];
int main()
{
while(~scanf("%d",&T))
{
while(T--)
{
int sum=0;
scanf("%d %d",&n,&k);
for(int i=1;i<=k;i++)
{
scanf("%d %d",&f[i].a,&f[i].b);
sum+=(f[i].a*f[i].b);
}
memset(c1,0,sizeof c1);
memset(c2,0,sizeof c2);
c1[0]=1;
for(int i=1;i<=k;i++)
{
for(int j=0;j<=sum;j++)
{
for(int k=0;k+j<=n&&k<=f[i].a*f[i].b;k+=f[i].a)
c2[k+j]+=c1[j];
}
for(int j=0;j<=n;j++)
{
c1[j]=c2[j];
c2[j]=0;
}
}
printf("%d\n",c1[n]);
}
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
标签:
原文地址:http://www.cnblogs.com/mengfanrong/p/4726788.html