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 8101int dp[N][M],dp2[N][M];void pre() {for(int i=1;i<=9;++i) dp[i][i*i]=1,dp2[i][i*i]=i;for(int i=1;i<N;++i)for(int j=1;j<M;++j)if(dp[i][j] && dp[i][j]!=100)for(int k=1;k<=9;++k)if(!dp[i+k][j+k*k] || dp[i+k][j+k*k]>dp[i][j]+1){dp[i+k][j+k*k]=dp[i][j]+1;dp2[i+k][j+k*k]=k;}else if(dp[i+k][j+k*k]==dp[i][j]+1) 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 0; }
转载于:https://www.cnblogs.com/TheRoadToTheGold/p/8453836.html
hdu 3022 Sum of Digits相关推荐
- codeforces 1060b Maximum Sum of Digits(思维题)
You are given a positive integer n Let S(x) be sum of digits in base 10 representation of x, for exa ...
- 【 CodeForces - 1060B 】Maximum Sum of Digits(思维,构造)
题干: You are given a positive integer nn. Let S(x)S(x) be sum of digits in base 10 representation of ...
- HDU.1001 Sum Problem
原题 HDU.1001 Sum Problem 分类 杂题 题意 计算从1到正整数n的累加和. 输入/输出 要求与格式 输入内容 每行输入一个正整数 输出结果 结果为累加和 输出格式 每个输出结果独占 ...
- CF489C Given Length and Sum of Digits
题目: Given Length and Sum of Digits ,哈哈,我们今天来看一道比较简单的贪心题,虽然比较简单,但是如果不仔细的话很容易出错的额,这是选自codeforce 489C上的 ...
- 第六章第二题(求一个整数各位数字之和)(Sum the digits in an integer)
*6.2(求一个整数各位数字之和)编写一个方法,计算一个整数各位数字之和.使用下面的方法头: public static int sumDigits(long n) 例如:sumDigits(234) ...
- cf489c Given Length and Sum of Digits...
cf489c Given Length and Sum of Digits... 题目描述 You have a positive integer m and a non-negative integ ...
- hdu 1258 Sum It Up(回溯算法)
题意:从给定的n个正整数中选出m个数(m <= n)使得这m个数的和为给定的total 解法:回溯 /* Author: ACb0y Date: 2010-11-11 ProblemId: hd ...
- 【HZNUOJ】【C系列3.8】Lucky Sum of Digits
[C系列3.8]Lucky Sum of Digits Time Limit: 10 s Memory Limit: 32 MB Submission:513 AC:156 ...
- hdu 4676 Sum Of Gcd 莫队+phi反演
Sum Of Gcd 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4676 Description Given you a sequence of ...
最新文章
- 干掉 FastJson
- 以编程方式进行NLog的配置【转】
- #数据集#:并发脑电图、心电图和多剂量经颅电刺激行为的数据集
- 黄聪:百度知道中对HTML字符实体、字符编号,开头字符的使用
- sql去除重复语句(转)
- 大话设计模式读后感之面向对象设计基础
- Oracle 原理: 初步认识程序包
- Python面向对象(三)
- Softmax(假神经网络)与词向量的训练
- 软件测试工作都干些什么?
- Eclipse alt+/语法不提示的解决方法
- Response实现文件下载
- Linux手机研发要过五大难关
- GO语言的进阶之路-流程控制
- Java做题错误知识点总结(頑張って)!
- python代码怎么样_python代码怎样清屏
- 微信多开软件苹果版_苹果(iphone)微信双开软件|ios系统福利来了
- 易语言-VB keypress事件中键盘上每个键的KeyAscii值
- Nginx 配置域名
- 木马手工查杀和隐藏控制技术分析
热门文章
- opencv第三方库JAVA接口,SpringBoot使用OpenCV示例总结
- mysql from unixtime_mysql 错误总结 和FROM_UNIXTIME用法
- 宿舍管理系统部分代码实现
- 实战渗透 | 向吃鸡外挂站开炮
- 删除mysql数据库中所有表
- java图像处理之幂律变换
- 深入理解Spark 2.1 Core (七):Standalone模式任务执行的原理与源码分析
- 将Python脚本打包成可执行文件
- javaweb学习总结(五):Servlet开发(一)
- 【windows】windows系统下,在任务管理器的进程选项卡中查看PID/任务管理器怎么查看PID...