递推DP URAL 1353 Milliard Vasya's Function
/*
题意:1~1e9的数字里,各个位数数字相加和为s的个数
递推DP:dp[i][j] 表示i位数字,当前数字和为j的个数
状态转移方程:dp[i][j] += dp[i-1][j-k],为了不出现负数
改为:dp[i][j+k] += dp[i-1][j]
*/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std; const int MAXN = 1e4 + ;
const int INF = 0x3f3f3f3f;
int dp[][]; int main(void) //URAL 1353 Milliard Vasya's Function
{
//freopen ("F.in", "r", stdin); int s;
while (scanf ("%d", &s) == )
{
memset (dp, , sizeof (dp)); dp[][] = ;
for (int i=; i<=; ++i)
{
for (int j=; j<=s; ++j)
{
if (dp[i-][j])
{
for (int k=; k<=; ++k) dp[i][j+k] += dp[i-][j];
} }
} if (s == ) dp[][s] += ;
printf ("%d\n", dp[][s]);
} return ;
}
递推DP URAL 1353 Milliard Vasya's Function的更多相关文章
- ural 1353. Milliard Vasya's Function(dp)
1353. Milliard Vasya's Function Time limit: 1.0 second Memory limit: 64 MB Vasya is the beginning ma ...
- ural 1353. Milliard Vasya's Function(背包/递归深搜)
1353. Milliard Vasya's Function Time limit: 1.0 second Memory limit: 64 MB Vasya is the beginning ma ...
- URAL 1353 Milliard Vasya's Function(DP)
题目链接 题意 : 让你找出1到10^9中和为s的数有多少个. 思路 : 自己没想出来,看的题解,学长的题解报告 题解报告 //URAL 1353 #include <iostream> ...
- ural 1353. Milliard Vasya's Function
http://acm.timus.ru/problem.aspx?space=1&num=1353 #include <cstdio> #include <cstring&g ...
- 递推DP URAL 1017 Staircases
题目传送门 /* 题意:给n块砖头,问能组成多少个楼梯,楼梯至少两层,且每层至少一块砖头,层与层之间数目不能相等! 递推DP:dp[i][j] 表示总共i块砖头,最后一列的砖头数是j块的方案数 状态转 ...
- 递推DP URAL 1260 Nudnik Photographer
题目传送门 /* 递推DP: dp[i] 表示放i的方案数,最后累加前n-2的数字的方案数 */ #include <cstdio> #include <algorithm> ...
- 递推DP URAL 1119 Metro
题目传送门 /* 题意:已知起点(1,1),终点(n,m):从一个点水平或垂直走到相邻的点距离+1,还有k个抄近道的对角线+sqrt (2.0): 递推DP:仿照JayYe,处理的很巧妙,学习:) 好 ...
- 递推DP URAL 1031 Railway Tickets
题目传送门 /* 简单递推DP:读题烦!在区间内的都更新一遍,dp[]初始化INF 注意:s1与s2大小不一定,坑! 详细解释:http://blog.csdn.net/kk303/article/d ...
- 递推DP URAL 1167 Bicolored Horses
题目传送门 题意:k个马棚,n条马,黑马1, 白马0,每个马棚unhappy指数:黑马数*白马数,问最小的unhappy值是多少分析:dp[i][j] 表示第i个马棚放j只马的最小unhappy值,状 ...
随机推荐
- wordpress自定义后台用户联系方式 添加qq、微博、微信
在 WordPress 后台,个人设置(Profile)中,可以设置电子邮件和 Website,如何添加国人常用的 QQ, 微博,微信呢? <?php /* Plugin Name: Custo ...
- centos安装配置nginx
1.安装gcc yum install gcc 2.安装PCRE,zlib,OpenSSL(其中devel,是develop开发包的意思) yum install -y pcre pcre-devel ...
- 第3章 K近邻法
参考: http://www.cnblogs.com/juefan/p/3807713.html http://blog.csdn.net/v_july_v/article/details/82036 ...
- HLG2062(make,heap问题)
最小的n个和 Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 129(37 users) Total Accepted: 35(29 u ...
- Windows下的git配置
需要的配置: 1.C:\Program Files\Git\etc\git-completion.bash: alias ls='ls --show-control-chars --color=aut ...
- Python多线程(2)——线程同步机制
本文介绍Python中的线程同步对象,主要涉及 thread 和 threading 模块. threading 模块提供的线程同步原语包括:Lock.RLock.Condition.Event.Se ...
- Java for LeetCode 024 Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2-& ...
- 猪八戒吃西瓜(wmelon)-排序-查找
问题 A: 猪八戒吃西瓜(wmelon) 时间限制: 1 Sec 内存限制: 64 MB提交: 30 解决: 14[提交][状态][讨论版] 题目描述 有一天,贪吃的猪八戒来到了一个大果园,果园里 ...
- Gym 100801E Easy Arithmetic (思维题)
题目:传送门.(需要下载PDF) 题意:给定一个长度不超过1000的字符串表达式,向该表达式中加入'+'或'-',使得表达式的值最大,输出该表达式. 题解:比如300-456就改成300-4+56,遇 ...
- Light OJ 1253 Misere Nim (尼姆博弈(2))
LightOJ1253 :Misere Nim 时间限制:1000MS 内存限制:32768KByte 64位IO格式:%lld & %llu 描述 Alice and Bob ar ...