uva11357 Matches
Matches
题意: 给你n根matches, 你可以拼出多少个数字0~9. 不必全部用完.
解题思路:
1. 计数题, 本题可以用图来理解. 把"已经使用了i根matches"看成状态, 这样就可以得到一个图.
每次从前往后在添加一个数字x时, 状态就从i变成i+c[x](c[x]拼x需要多少根matches);
2. 有了上面的基础, 可以得到状态方程: dp[i+c[x]] += dp[i];(dp[i]就是从0到节点i的路径数目)
那么结果是: dp[1]+dp[2]+...+dp[n](因为matches不必全部用完, 加法原理);
3. 最后要注意的是前导0是不允许的, 所以当n>=6的时候全部要加上1;
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int c[]={,,,,,,,,,},a[],b[],h[];
struct node{
int len;
int zu[];
node operator + (const node x)const{
memset(a,,sizeof(a));
memset(b,,sizeof(b));
memset(h,,sizeof(h));
node res;res.len=;
for(int i=,j=x.len;i<=x.len;i++,j--)a[i]=x.zu[j];
for(int i=,j=len;i<=len;i++,j--)b[i]=zu[j];
int l=max(len,x.len);
for(int i=;i<=l;i++){
h[i]+=a[i]+b[i];
h[i+]+=h[i]/;
h[i]%=;
}
while(h[l+]){
l++;
h[l+]=h[l]/;
h[l]%=;
}
res.len=l;
for(int i=,j=l;i<=l;i++,j--)res.zu[i]=h[j];
return res;
}
}d[],ans;
int main(){
freopen("Cola.txt","r",stdin);
int n;
while(scanf("%d",&n)!=EOF){
memset(d,,sizeof(d));
ans.len=;
d[].len=;d[].zu[]=;
for(int i=;i<=n;i++)
for(int j=;j<;j++)
if(!(i==&&j==)&&i+c[j]<=n)d[i+c[j]]=d[i+c[j]]+d[i];
for(int i=;i<=n;i++){
ans=ans+d[i];
}
for(int i=;i<=ans.len;i++)printf("%d",ans.zu[i]);
printf("\n");
} }
TLE
uva11357 Matches的更多相关文章
- keil MDK error: L6236E: No section matches selector - no section 错误
今天板子刚到,新建的第一个工程就报错了. .\Objects\cse.sct(7): error: L6236E: No section matches selector - no section t ...
- 解决Android中No resource found that matches android:TextAppearance.Material.Widget.Button.Inverse问题
解决Android中No resource found that matches android:TextAppearance.Material.Widget.Button.Inverse问题http ...
- HDU5456 Matches Puzzle Game(DP)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5456 Description As an exciting puzzle game for ...
- Matches正则使用提取内容
用VS新建WinForm程序,窗体上是三个文本框和一个按钮.可以自己构造正则表达式,自己修改匹配内容 正则表达是要提取的部分为hewenqitext 代码如下: using System; using ...
- js之 matches (可以取代jq的 delegate 方法)
问题:请给#wrap 下面的子元素添加点击事件! <div id="wrap"> <a class="btn" href="http ...
- Owin SelfHost Asp.net WebApi 遇到 No type was found that matches the controller named 'ControllerName' 异常的解决方案
问题背景:在使用普通的SelfHost时,调用其它工程的dll(其实就是把WebApi写到一个单独的工程方便管理),通过加载其他工程的dll然后再访问webapi是没有问题的. 但是在使用Owin S ...
- uva 11357 Matches
// uva 11357 Matches // // 题目大意: // // 给你n个火柴,用这n个火柴能表示的非负数有多少个,不能含有前导零 // // 解题思路: // // f[i] 表示正好用 ...
- android中出现Error retrieving parent for item: No resource found that matches the Theme.AppCompat.Light
styles.xml中<style name="AppBaseTheme" parent="Theme.AppCompat.Light">提示如下错 ...
- error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'.
error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCom ...
随机推荐
- MySql索引建立规则
为了使索引的使用效率更高,在创建索引时,必须考虑在哪些字段上创建索引和创建什么类型的索引.本小节将向读者介绍一些索引的设计原则. 1.选择唯一性索引 唯一性索引的值是唯一的,可以更快速的通过该索引来确 ...
- git功能速查
http://gitbook.liuhui998.com/index.html git rebase:在本地变基.将本地所有的修改应用到另一个分支上 git merge:在本地合并分支 git bra ...
- 调用微信接口token的问题
前言 微信的影响力众所周知,越来越多的人也都离不开它,工作,生活,社交的好帮手.相信大家对微信公众号,小程序也都不陌生,那么在开发公众号,小程序的时候需要调用到微信的接口,固然就会遇到token的问题 ...
- mini2440移植uboot 2011.03(下)
参考博文: <u-boot-2011.03在mini2440/micro2440上的移植> 移植(五)添加nand支持: host@debian:~/soft/mini2440/u-boo ...
- g2o的一般过程
1.自己定义顶点类.边类或者用已经有的.1.1定义顶点例子class CurveFittingVertex: public g2o::BaseVertex<3, Eigen::Vector3d& ...
- 算法(Algorithms)第4版 练习 1.3.21
方法实现: //1.3.21 /** * find if some node in the list has key as its item field * * @param list the lin ...
- 如何让你的手机U盘集PE工具、系统安装、无线破解等众多功能于一身
不久前,手里的U盘坏了,于是乎,又在网上淘了一个Type-C U盘,刚好手机电脑都可以用. 那么现在U有了,我们要做什么呢? 第一:让U盘插在手机上时,可以供手机读写,实现手机存储扩容,随插随用,简单 ...
- zabbix增加服务器tcp监控
zabbix server web界面,需要导入 tcp 监控模板 操作步骤: Configuration --> Templates --> Import ,选择 本地的 zb ...
- python之tkinter_2
关于tkinter的组件介绍,这篇博客很详细: https://www.cnblogs.com/aland-1415/p/6849193.html tkinter is to make interfa ...
- JS遍历ChexkBoxList
var cboxs = $("#cblAuth input[type=checkbox]"); ; ; i < cboxs.length; i++) { if (cboxs[ ...