UVA 10721 Bar Codes(DP,整数拆分)

A bar-code symbol consists of alternating dark and light bars, starting
with a dark bar on the left. Each bar is a number of units wide.
Figure 1 shows a bar-code symbol consisting of 4 bars that extend
over 1 + 2 + 3 + 1 = 7 units.
In general, the bar code BC(n, k, m) is the set of all symbols with
k bars that together extend over exactly n units, each bar being at
most m units wide. For instance, the symbol in Figure 1 belongs to
BC(7,4,3) but not to BC(7,4,2). Figure 2 shows all 16 symbols in
BC(7,4,3). Each ‘1’ represents a dark unit, each ‘0’ a light unit.
0: 1000100 | 4: 1001110 | 8: 1100100 | 12: 1101110
1: 1000110 | 5: 1011000 | 9: 1100110 | 13: 1110010
2: 1001000 | 6: 1011100 | 10: 1101000 | 14: 1110100
3: 1001100 | 7: 1100010 | 11: 1101100 | 15: 1110110
Figure 2: All symbols of BC(7,4,3)
Input
Each input will contain three positive integers n, k, and m (1 ≤ n, k, m ≤ 50).
Output
For each input print the total number of symbols in BC(n, k, m). Output will fit in 64-bit signed integer

Sample Input
7 4 3
7 4 2
Sample Output
16
4
题目大意:大小为n的数拆成m组,每组最大k个
ac代码
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<limits.h>
#define N 100010
#define mod 1000000
#define LL long long
using namespace std;
LL dp[55][55];
void DP(int n,int m,int k)
{
    int i,j,t;
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(i=1;i<=m;i++)
    {
        for(j=1;j<=n;j++)
        {
            for(t=1;t<=k&&t<=j;t++)
                dp[i][j]+=dp[i-1][j-t];
        }
    }
}
int main()
{
    int n,m,k;
    while(scanf("%d%d%d",&n,&m,&k)!=EOF)
    {
       // int i,j,k;
        DP(n,m,k);
        printf("%lld\n",dp[m][n]);
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值