统计硬币 hdu-2566

假设一堆由1分、2分、5分组成的n个硬币总面值为m分,求一共有多少种可能的组合方式(某种面值的硬币可以数量可以为0)。

Input 输入数据第一行有一个正整数T,表示有T组测试数据;
接下来的T行,每行有两个数n,m,n和m的含义同上。
Output 对于每组测试数据,请输出可能的组合方式数;
每组输出占一行。
Sample Input
2
3 5
4 8
Sample Output
1
2

//暴力穷举

#include <iostream>
#include <bits/stdc++.h>

using namespace std;


int main()
{
    int t,a,n;
    cin>>t;
    while(t--)
    {
      int sm=0;
      cin>>a>>n;
        for(int i=0;i<=n;i++)
        {
           for(int j=0;j<=n/2;j++)
           {
              for(int k=0;k<=n/5;k++)
              {
                 if((i+j+k)==a&&(i+2*j+5*k)==n)
                 sm++;
              }
           }
        }
        cout<<sm<<endl;
    }
    return 0;
}


猜你喜欢

转载自blog.csdn.net/stanmae/article/details/80244902
今日推荐