http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2777&cid=1219

这题不会,看了别人的代码

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int dp[32770];
int main()
{
    int n,i,j;
    int w[4]= {0,1,2,3};
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(i=1; i<=3; i++)
    {
        for(j=w[i]; j<=32768; j++)
        {
            dp[j]=dp[j]+dp[j-w[i]];
        }
    }
    while(scanf("%d",&n)!=EOF)
    {
        printf("%d\n",dp[n]);
    }
    return 0;
}

 http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2934

这题就是换零钱的变形

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int main()
{
    int T,n,dp[501];
    int w[21]= {0,1,4,9,16,25,36,49,64,81,100,121,144,169,196,225,256,289,324,361,400};
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(int i=1; i<=20; i++)
    {
        for(int j=w[i]; j<=500; j++)
        {
            dp[j]=dp[j]+dp[j-w[i]];
        }
    }
    while(scanf("%d",&n)!=EOF)
    {
        printf("%d\n",dp[n]);
    }
    return 0;
}

 

相关文章:

  • 2021-07-23
  • 2022-12-23
  • 2019-01-13
  • 2021-06-24
  • 2021-12-03
  • 2022-01-19
  • 2021-05-17
  • 2021-05-20
猜你喜欢
  • 2021-09-16
  • 2021-06-26
  • 2021-12-24
  • 2022-12-23
  • 2021-09-15
  • 2021-12-05
  • 2021-06-29
相关资源
相似解决方案