zoukankan      html  css  js  c++  java
  • UVA 10313 Pay the Price

    其实这个题目可以用原来的换硬币的方法来解决,但是这个题目是也是一个这样的问题:求把一个整数i最多拆分成j个数时的方法数。

    f[i][j]表示把一个整数i最多拆分成j个数时的方法数,f[0][0]=1;状态转移方程是f[i][j]=f[i-j][j]+f[i][j-1].

    下面贴代码:

    View Code
     1 #include <stdio.h>
     2 #include <string.h>
     3 long long int f[301][301];
     4 char s[100];
     5 int main()
     6 {
     7     int a,b,c,i,j;
     8     memset(f,0,sizeof(f));
     9     f[0][0] = 1;
    10     for(i = 0;i <= 300;i++)
    11         for(j = 1;j <= 300;j++)
    12         {
    13             f[i][j] = f[i][j - 1];
    14             if(i >= j)
    15                 f[i][j] += f[i - j][j];
    16         }
    17     while(gets(s) != NULL)
    18     {
    19         switch(sscanf(s,"%d%d%d",&a,&b,&c))
    20         {
    21         case 1:
    22             printf("%lld\n",f[a][a]);
    23             break;
    24         case 2:
    25             b = b > 300 ? 300 : b;
    26             printf("%lld\n",f[a][b]);
    27             break;
    28         default:
    29             b = b > 300 ? 300 : b;
    30             c = c > 300 ? 300 : c;
    31             if(b)
    32                 printf("%lld\n",f[a][c] - f[a][b - 1]);
    33             else
    34                 printf("%lld\n",f[a][c]);
    35         }
    36     }
    37     return 0;
    38 }
  • 相关阅读:
    [POI2014]FarmCraft
    [POI2014]Solar Panels
    Luogu P2824 [HEOI2016/TJOI2016]排序
    CF903G Yet Another Maxflow Problem
    CF901C Bipartite Segments
    CF749E Inversions After Shuffle
    ARC068C Snuke Line
    BZOJ3747 [POI2015]Kinoman
    SA-IS
    简单字符串
  • 原文地址:https://www.cnblogs.com/zhexipinnong/p/2497506.html
Copyright © 2011-2022 走看看