首页 > 其他 > 详细

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

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

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 + "种");
    }
}
使用动态规划更合适!

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!