uva10943 How do you add?

题意:把K个不超过N的非负整数加起来,使得它们的和为N,有多少种方法

思路

  • 令dp[i][j]为和为i用了j个数的方案数,那么转移就是dp[i][j]=dp[i-1][j]+dp[i][j-1]
  • dp[i-1][j]表示在和为i-1用了j个数的方案中,最后一个数+1
  • dp[i][j-1]表示在和为i用了j-1个数的方案中,加上一个0

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3
 4 int dp[101][101];
 5 const int mod = 1e6;
 6 int main()
 7 {
 8     for (int i = 1;i<=100;i++)
 9     {
10         dp[i][1]=1;
11         dp[1][i]=i;
12     }
13     for (int i = 2;i<=100;i++)
14         for (int j = 2;j<=100;j++)
15             dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
16     int n,k;
17     while (scanf("%d%d",&n,&k)!=EOF && n+k)
18     {
19         printf("%d\n",dp[n][k]);
20     }
21 }

原文地址:https://www.cnblogs.com/ljy08163268/p/11704920.html

时间: 2024-11-08 15:55:20

uva10943 How do you add?的相关文章

《算法竞赛入门经典——训练指南》第二章题库

UVa特别题库 UVa网站专门为本书设立的分类题库配合,方便读者提交: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=442 注意,下面注有"extra"的习题并没有在书中出现,但在上面的特别题库中有,属于附加习题. 基础练习 (Basic Problems) UVa11388 GCD LCM UVa11889 Benefit UVa10943 How do y

设置IIS,使其只能接收国内的用户访问(IP限制)

IP明细参考 先找到国内所有的IP http://ipblock.chacuo.net/view/c_CN 执行脚本 IIS白名单设置 powershell #国内IP白名单 Import-Module WebAdministration $webSite = 'TEST.WEBSITE' function Func { param ( $ipAddr, $ipMask ) # Add new IP CIDR entry to restrictions to website Test Add-W

backup, file manipulation operations (such as ALTER DATABASE ADD FILE) and encryption changes on a database must be serialized.

昨天在检查YourSQLDba备份时,发现有台数据库做备份时出现了下面错误信息,如下所示: <Exec>   <ctx>yMaint.ShrinkLog</ctx>   <inf>Log Shrink</inf>   <Sql> --  ======================================================================== -- Shrink of log file E:\SQ

2、Add Two Numbers

1.Add Two Numbers--这是leedcode的第二题: You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. Input:

FragmentTransaction的add(),replace(),以及show(),hide()

最近在做一个Android的电商App,之前一直使用FragmentTransaction的add(),hide()和show()来控制主页的显示与隐藏.最近发现一个问题,因为show()和hide() 来控制显示隐藏的话是不走Fragment的onResume方法的,而如果使用replace()的话就是全部Fragment都走onResume()方法.这就无法满足我一部分Fragment点击刷新而另一部分不刷新的要求.最后发现,通过定义两个FragmentManager和FragmentTra

[LeetCode In C++] 2. Add Two Numbers

题目: You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. Input: (2 -> 4 -> 3) + (5 -> 6 -&

There is no Action mapped for namespace [/user] and action name [user!add] associated with context p

使用struts2.3进行动态方法调用时出现: There is no Action mapped for namespace [/user] and action name [user!add] associated with context path错误,原因是 (1)DMI可能导致安全问题 (2)DMI与通配符方法功能有重叠,因此该版本Struts2默认关闭DMI,需要在struts.xml中加一句 <constant name="struts.enable.DynamicMetho

Add Again(重复元素排序)

Add Again Input: Standard Input Output: Standard Output Summation of sequence of integers is always a common problem in Computer Science. Rather than computing blindly, some intelligent techniques make the task simpler. Here you have to find the summ

ArrayList之add(E e)学习笔记

/**  * Appends the specified element to the end of this list.  *  * @param e element to be appended to this list  * @return <tt>true</tt> (as specified by {@link Collection#add})  */ public boolean add(E e) {     ensureCapacityInternal(size +