码迷,mamicode.com
首页 > 其他好文 > 详细

核工业计算机应用研究所笔试题。

时间:2017-04-04 00:46:17      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:system   试题   bsp   函数   test   方式   内容   使用   人民币   

1元,5元,10元的人民币,组合成100元
使用《组合数学》里面的生成函数的方式实现(生成函数很暴力,生成函数的具体内容非常复杂):
假设1*x + 5*y + 10*z == 100
x , y , z 的取值范围为 : x = [0,100]  y = [0,20]  z = [0,10]
public class CombinationTest
{
    public static void main(String[] args)
    {
        int count = 0;
        
        int time = 0;
        
        for(int x = 0;x <= 100;x++)
        {
            for(int y = 0;y <= 20;y++)
            {
                for(int z = 0;z <= 10;z++)
                {
                    if(1*x + 5*y + 10*z == 100)
                    {
                        count++;
                    }
                    time++;
                }
            }
        }
        System.out.println("循环的次数有:" + time + "次");
        
        System.out.println("组合的方式有:" + count + "种");
    }
}
使用动态规划更合适!

核工业计算机应用研究所笔试题。

标签:system   试题   bsp   函数   test   方式   内容   使用   人民币   

原文地址:http://www.cnblogs.com/javacatalina/p/6664108.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!