hdu 3022 Sum of Digits
http://acm.hdu.edu.cn/showproblem.php?pid=3022
题意:
#include<cstdio>
#include<algorithm> using namespace std; #define N 901
#define M 8101 int dp[N][M],dp2[N][M]; void pre()
{
for(int i=;i<=;++i) dp[i][i*i]=,dp2[i][i*i]=i;
for(int i=;i<N;++i)
for(int j=;j<M;++j)
if(dp[i][j] && dp[i][j]!=)
for(int k=;k<=;++k)
if(!dp[i+k][j+k*k] || dp[i+k][j+k*k]>dp[i][j]+)
{
dp[i+k][j+k*k]=dp[i][j]+;
dp2[i+k][j+k*k]=k;
}
else if(dp[i+k][j+k*k]==dp[i][j]+) dp2[i+k][j+k*k]=min(dp2[i+k][j+k*k],k);
} int main()
{
pre();
int T,n,m,d;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
if(n>=N || m>=M || !dp[n][m]) printf("No solution\n");
else
{
while(n)
{
printf("%d",d=dp2[n][m]);
n-=d;
m-=d*d;
}
putchar('\n');
}
}
return ;
}
hdu 3022 Sum of Digits的更多相关文章
- CodeForces 489C Given Length and Sum of Digits... (贪心)
Given Length and Sum of Digits... 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/F Descr ...
- Sum of Digits / Digital Root
Sum of Digits / Digital Root In this kata, you must create a digital root function. A digital root i ...
- Maximum Sum of Digits(CodeForces 1060B)
Description You are given a positive integer nn. Let S(x) be sum of digits in base 10 representation ...
- Codeforces Round #277.5 (Div. 2)C——Given Length and Sum of Digits...
C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabyte ...
- CodeForces 1060 B Maximum Sum of Digits
Maximum Sum of Digits You are given a positive integer n. Let S(x)S(x) be sum of digits in base 10 r ...
- Hdu3022 Sum of Digits
Sum of Digits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- HDOJ(HDU).1258 Sum It Up (DFS)
HDOJ(HDU).1258 Sum It Up (DFS) [从零开始DFS(6)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双 ...
- codeforces#277.5 C. Given Length and Sum of Digits
C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabyte ...
- cf#513 B. Maximum Sum of Digits
B. Maximum Sum of Digits time limit per test 2 seconds memory limit per test 512 megabytes input sta ...
随机推荐
- 【原创】梵高油画用深度卷积神经网络迭代10万次是什么效果? A neural style of convolutional neural networks
作为一个脱离了低级趣味的码农,春节假期闲来无事,决定做一些有意思的事情打发时间,碰巧看到这篇论文: A neural style of convolutional neural networks,译作 ...
- iOSApp上下有黑边
如图: 这种情况就是没有启动页导致的,加了启动页图片之后就不会再出现了. 设置启动页的方法: http://www.cnblogs.com/BK-12345/p/5218229.html 有的人说我加 ...
- Apache服务器出现Forbidden 403错误提示的解决方法总结
在配置Linux的 Apache服务时,经常会遇到http403错误,我今天配置测试时也出现了,最后解决了,总结了一下.http 403错误是拒绝访问的意思,有很多原因的.还有,这些问题在win平台的 ...
- PAT甲题题解-1030. Travel Plan (30)-最短路+输出路径
模板题最短路+输出路径如果最短路不唯一,输出cost最小的 #include <iostream> #include <cstdio> #include <algorit ...
- tomcat运行JSP时产生的错误:”javax.servlet.servletexception: java.lang.nosuchmethoderror”
这个错误其实是多次重复编译JAVA文件导致的,需要clean操作,简单的来说就是删除tomcat下work文件夹中工作空间,也可以理解为自己的虚拟路径,比如我运行的jsp的路径:localhost:8 ...
- 《Linux内核分析》第三周
[李行之原创作品 转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000] <Linux内 ...
- linq to sql中的自动缓存(对象跟踪)
linq to sql中,对于同一个DataContext上下文环境,根据表主键选择记录时(当然这里所指的“记录”会自动转成“对象”),如果该记录已经被select过,默认情况下会被自动缓存下来,下次 ...
- Activiti源码学习:ExecutionListener与TaskListener的区别
/** Callback interface to be notified of execution events like starting a process instance, * ending ...
- thinkphp5报错
thinkPHP5配置nginx环境无法打开(require():open_basedirrestrictionineffect.File(/mnt/hgfs/ro (2018-07-19 22:05 ...
- 用node编写cli工具
cli是command-line interface的缩写,即命令行工具,常用的vue-cli, create-react-app, express-generator 等都是cli工具. 本文以自己 ...