一道算法题,请大家帮忙,help, 以下有1角,2角,5角,1元,2元,5元,10元问:有多少种方式能刚好组合成100元整?(包括1000个1角也算一种组合)请以C#方式写出来,并注明注释,可以的话讲讲原理,谢谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 动态规划可以,这是以前写的一个程序using System;namespace CSharpTest{ class Program { static int[] Items; static long[,] Matrix; static void Main(string[] args) { Items = new int[] { 1000, 500, 200, 100, 50, 20, 10, 5 ,2 ,1}; int value = 10000; Matrix = new long[value + 1, Items.Length]; Console.WriteLine(GetCount(0, value)); Console.ReadKey(); } static long GetCount(int currentIndex, int remain) { //如果金额小于0,返回0种 if (remain < 0) return 0; //如果金额=0,或算到1元了则正好可以被兑换 if (remain == 0 || currentIndex == Items.Length - 1) return 1; if (Matrix[remain, currentIndex] == 0) Matrix[remain, currentIndex] = GetCount(currentIndex + 1, remain) + GetCount(currentIndex, remain - Items[currentIndex]); return Matrix[remain, currentIndex]; } }} 请写注释啊int value = 10000;10000从哪来的 谁有C#基于windows的窗体编程视频教程? 来晒晒 能不能在中括号内匹配多个字符串?。。。 请问这种Clik事件可不可以简化 咋导入和导出Excel 里的数据 关于Dropdownlist数据绑定的操作问题!!!!!! 关于DataTable的问题 请问大家怎么才能在子窗口同时画一个同样的东西 序列化问题. 请教大神,有“ dic["192.168.1.15:5558"].send(byte[]) ”方面详细解说嘛? VB转NET学什么最好? 高手,请问一下一个正则表示式怎写。 谁有刘汝佳算法竞赛入门经典这本书的习题答案
{
class Program
{
static int[] Items;
static long[,] Matrix; static void Main(string[] args)
{
Items = new int[] { 1000, 500, 200, 100, 50, 20, 10, 5 ,2 ,1};
int value = 10000;
Matrix = new long[value + 1, Items.Length];
Console.WriteLine(GetCount(0, value));
Console.ReadKey();
} static long GetCount(int currentIndex, int remain)
{
//如果金额小于0,返回0种
if (remain < 0)
return 0; //如果金额=0,或算到1元了则正好可以被兑换
if (remain == 0 || currentIndex == Items.Length - 1)
return 1; if (Matrix[remain, currentIndex] == 0)
Matrix[remain, currentIndex] = GetCount(currentIndex + 1, remain) + GetCount(currentIndex, remain - Items[currentIndex]); return Matrix[remain, currentIndex];
}
}
}
int value = 10000;
10000从哪来的