更简单的做法:
定义状态dp[i][j]表示在已经用了i根火柴的情况下拼出来了剩余部分(是剩余部分,不是已经拼出来了的)为j(需要%m)的最大长度,一个辅助数组p[i][j]表示状态[i][j]的最高位
是往后添加k
dp[i][j]=max(dp[i][j],dp[i-c[k]][(j*10+k)%m]+1)
(这里应该要证明dp[i-c[k]][(j*10+k)%m]加了d%m=j,没证出来...
倒着枚举k,这样保证位数相同存更大的数

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std; const int maxn = ;
const int maxm = ; // dp[i][j] is the maximal length of the integer whose remainder is j (with at most i matches)
// p[i][j] is the maximal digit for state (i,j)
int n, m, dp[maxn][maxm], p[maxn][maxm]; int needs[] = { , , , , , , , , , }; int main(){
int kase = ;
while(scanf("%d%d", &n, &m) == ) {
printf("Case %d: ", ++kase); for(int i = ; i <= n; i++) //dp[i][j]=max(dp[i][j],dp[i-c[k]][(j*10+k)%m]+1)
for(int j = ; j < m; j++){ //注意枚举的是火柴数不是位数
int& ans = dp[i][j];
ans = p[i][j] = -;
if (j == ) ans = ;
for(int d = ; d >= ; d--)
if (i >= needs[d]){
int t = dp[i - needs[d]][(j * + d) % m]; if (t >= && t + > ans){ //t exist
ans = t + ;
p[i][j] = d;
}
}
} if (p[n][] < ) printf("-1");
else {
int i = n, j = ;
for(int d = p[i][j]; d >= ; d = p[i][j]){
printf("%d", d);
i -= needs[d];
cout<<"x"<<j<<endl;
j = (j * + d) % m;
//printf("%d", j);
}
}
printf("\n");
}
return ;
}

uva12105 Bigger is Better的更多相关文章

  1. spark - tasks is bigger than spark.driver.maxResultSize

    Error ERROR TaskSetManager: Total size of serialized results of 8113 tasks (1131.0 MB) is bigger tha ...

  2. MYSQL 内存报错 Use 'mysqld --thread_stack=#' to specify a bigger stack.

    今天在使用mysql的过程中,连接数据库始终无法成功 最后发现是数据库无法执行增加修改的操作 :错误代码 Thread stack overrun:  11552 bytes used of a 13 ...

  3. 数据库执行sql报错Got a packet bigger than 'max_allowed_packet' bytes及重启mysql

    准备在mysql上使用数据库A,但mysql5经过重装后,上面的数据库已丢失,只得通过之前备份的A.sql重新生成数据库A. 1.执行sql报错 在执行A.sql的过程中,出现如下错误:Got a p ...

  4. HDU2929 Bigger is Better[DP 打印方案 !]

    Bigger is Better Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  5. HDOJ 2929 Bigger is Better

    DP....好难的DP... Bigger is Better Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  6. don't forget the bigger picture

    Imagine a circle that contains all of human knowledge: By the time you finish elementary school, you ...

  7. Got a packet bigger than 'max_allowed_packet' bytes

    昨天用导入数据的时候发现有的地方有这个错误.后来才发现我用RPM包装的MYSQL配置文件里面有old_passwords=1去掉就可以了. Got a packet bigger than ‘max_ ...

  8. Navicat导入数据时发生了报错 --- 1153 - Got a packet bigger than 'max_allowed的处理办法

    今天我在使用Navicat导入.sql文件数据时,发现本来是80万条的数据,结果只导入了10万条左右,而且在其错误信息日志中,我发现了这样一条错误:1153 - Got a packet bigger ...

  9. Navicat 导入数据报错 --- 1153 - Got a packet bigger than 'max_allowed_packet' bytes

    在用Navicat导入SQL文件时报错:MySql 错误 Err [Imp] 1153 - Got a packet bigger than 'max_allowed_packet' bytes 查了 ...

随机推荐

  1. codeforces 724D

    注意到要字典序最小,从而变为水题. 从a选到z,每次必然是先看选部分当前字符x是否能满足覆盖,若不能则选上所有的字母x,不然break,输出答案. 进行26次dp即可. #include <cs ...

  2. List集合与Array数组之间的互相转换

    1.数组转换成List集合 采用java中集合自带的asList()方法就可以完成转换了 String[] array = new String[] {"zhu", "w ...

  3. ubuntu的NAT方式上网配置

    vm菜单栏虚拟机--->设置---->网络适配器---->勾选NAT方式 vi /etc/network/interfaces修改配置文件如下: auto loiface lo in ...

  4. 51nod 1433【数学】

    思路: 不晓得阿,n%9==0即n数值各个位加起来要%9==0: 如果知道这个,那么%90==0就是末尾多个0就好了,那么后面就是随便搞吧: #include <stdio.h> #inc ...

  5. 了解Hypertable

    1.为什么要了解Hypertable, 因为全球最大的搜索引擎公司百度使用了Hypertable(http://www.baidu.com/s?wd=Hypertable),Hypertable类似于 ...

  6. python __builtins__ classmethod类 (11)

    11.'classmethod', 修饰符对应的函数不需要实例化,不需要 self 参数,但第一个参数需要是表示自身类的 cls 参数,可以来调用类的属性,类的方法,实例化对象等. class cla ...

  7. python property的2种使用方法

    一.property类 class Person(): def __init__(self, name): self.set_name(name) def get_name(self): return ...

  8. VS2019+ASP.NETCore+图表

    原帖学习踩坑:https://www.cnblogs.com/fzqm-lwz/p/9704973.html,主要根据大佬原帖内容,实现尝试,进行一些修改: 实现方式一:通过标记帮助程序将JS代码传到 ...

  9. C++类的默认函数

    在C++中,一个类有八个默认函数: 默认构造函数: 默认拷贝构造函数: 默认析构函数: 默认重载赋值运算符函数: 默认重载取址运算符函数: 默认重载取址运算符const函数: 默认移动构造函数(C++ ...

  10. Jquery | 基础 | 使用 jQuery 表单过滤选择器

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...