找回密码
 欢迎注册
查看: 13235|回复: 9

[讨论] puzzleup 9.23

[复制链接]
发表于 2009-9-25 07:22:02 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?欢迎注册

×
Coins

It is possible to reach every value from 1 to 50 (both inclusive) using at most two of the coins used in a country. What is the possible minimum value of the sum of all coins in this country?

If the same question was asked for values from 1 to 8, the answer would be 8 (1+3+4)

{1}, {1+1}, {3}, {4}, {1+4}, {3+3}, {3+4}, {4+4}

一个国家的硬币系统, 对于任意从1到50的价值, 都可以用至多两个硬币来表示(可重复使用同一个硬币值), 问所有不同价值的硬币的和的最小值是多少?
例子: 如果是从1到8, 和的最小值是8, 可以用如下三个硬币: 1, 3和4.

目前搜索的结果: 10个硬币没有解; 11个硬币, 最小值是141.  还可以更少吗?
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2009-9-25 08:57:01 | 显示全部楼层
不可以
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2009-9-25 08:59:14 | 显示全部楼层
直接逆推就能得到答案了
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2009-9-26 00:41:18 | 显示全部楼层
麻烦你写一下逆推的过程   多谢
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2009-9-26 14:56:31 | 显示全部楼层
sum=140: 1 2 3 4 5 6 7 8 9 10 11 12 25 37
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2009-9-26 14:57:38 | 显示全部楼层

  1. #define MAXDEPTH 20
  2. #define MAXSUM   145

  3. struct VALUE{
  4.     long long mask;
  5.     long long vlist;
  6.     int sum;
  7. };

  8. VALUE v[MAXDEPTH];

  9. void dump(int depth)
  10. {
  11.     int i;
  12.     printf("sum=%d:",v[depth].sum);
  13.     for(i=1;i<=50;i++){
  14.         if(v[depth].vlist&(1LL<<i)){
  15.             printf(" %d",i);
  16.         }
  17.     }
  18.     printf("\n");
  19. }

  20. void try_insert(int value, int depth)
  21. {
  22.     int i;
  23.     if(value+v[depth-1].sum>MAXSUM)return;
  24.     v[depth].mask=v[depth-1].mask|(1LL<<value);
  25.     v[depth].vlist=v[depth-1].vlist|(1LL<<value);
  26.     v[depth].sum=v[depth-1].sum+value;
  27.     for(i=1;i<=50;i++){
  28.         if(v[depth].vlist&(1LL<<i)){
  29.             int j=i+value;
  30.             if(j<=50){
  31.                 v[depth].mask|=1LL<<j;
  32.             }
  33.         }
  34.     }
  35.     for(i=1;i<=50;i++){
  36.         if((v[depth].mask&(1LL<<i))==0)
  37.             break;
  38.     }
  39.     int min_next=i;
  40.     if(min_next>50){
  41.         dump(depth);
  42.         return;
  43.     }
  44.     for(i=min_next;i>=value+1;i--){
  45.         try_insert(i,depth+1);
  46.     }
  47. }

  48. int _tmain(int argc, _TCHAR* argv[])
  49. {
  50.     int used=1;
  51.     int min_next=3;
  52.     int i;
  53.     v[0].mask=2LL|4LL;
  54.     v[0].sum=1;
  55.     v[0].vlist=2LL;
  56.     for(i=min_next;i>=used+1;i--){
  57.         try_insert(i,1);
  58.     }
  59.         return 0;
  60. }
复制代码

评分

参与人数 1鲜花 +3 收起 理由
wayne + 3

查看全部评分

毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2009-9-27 14:14:23 | 显示全部楼层
错了,唉。。。。
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2009-9-27 23:19:58 | 显示全部楼层
老兄现在排第几位呀?
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2009-10-1 22:30:57 | 显示全部楼层
俺是140.
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2012-3-9 11:09:12 | 显示全部楼层
6# mathe
代码很棒
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
您需要登录后才可以回帖 登录 | 欢迎注册

本版积分规则

小黑屋|手机版|数学研发网 ( 苏ICP备07505100号 )

GMT+8, 2024-5-17 18:18 , Processed in 0.049402 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表