HDU2082
程序员文章站
2022-03-15 18:20:50
...
常生成函数-模板题
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int num[30];
ll a[55],b[55];
int main()
{
int t;
scanf("%d",&t);
while(t--){
for(int i = 1;i <= 26;++ i) scanf("%d",&num[i]);
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(int i = 0;i <= num[1];++ i)
a[i] = 1;
for(int i = 2;i <= 26;++ i){
if(num[i] == 0) continue;
int weight = i;
for(int j = 0;j <= 50;++ j){
for(int k = 0;k <= num[i] && weight * k + j <= 50;++ k)
b[j+k*weight] += a[j];
}
for(int j = 0;j <= 50;++ j){
a[j] = b[j];
b[j] = 0;
}
}
/*for(int i = 1;i <= 50;++ i)
printf("%lld ",a[i]);
printf("\n");*/
ll ans = 0;
for(int i = 1;i <= 50;++ i)
ans += a[i];
printf("%lld\n",ans);
}
}
注意,把k+j <= 50 换成 weight*k+j,weight表示每个字母对应的权重
上一篇: Kotlin进阶之内联函数(Inline Functions)
下一篇: 单链表的操作(不带头节点)