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 ...
随机推荐
- linux 下 cat
[root@localhost Data]# cat << end > iptable> 3> 4> 5> > 6> end[root@local ...
- Spring事务超时时间可能存在的错误认识
摘自:http://jinnianshilongnian.iteye.com/blog/1986023, 感谢作者. 1.先看代码 1.1.spring-config.xml <bean id= ...
- BFC和haslayout(IE6-7)(待总结。。。)
支持BFC的浏览器(IE8+,firefox,chrome,safari) Block Formatting Context(块格式化上下文)是W3C CSS2.1规范中的一个慨念,在CSS3中被修改 ...
- 可信执行环境(TEE)介绍 与应用
原文:http://blog.csdn.net/wed110/article/details/53894927 可信执行环境(TEE,Trusted Execution Environment) 是G ...
- python当前工作文件夹中创建空的.txt文件
import os def new_txt(): a1='实线' b = os.getcwd() + '\\fazhandadao_test_txt\\' if not os.path.exists( ...
- centos6.3 安装python2.7.3
现在比较流行python2.7版本,centos6.3的默认版本是2.6.6,所以需要安装下2.7版本 1.下载安装python2.7 #wget http://www.python.org/ftp/ ...
- 搭建LoadRunner中的场景(三)场景的执行计划
所谓场景操作,包括初始化用户组.启动用户组各用户以及停止虚拟用户的全过程.依据设置不同,执行过程中可以最多有5类操作,分别是启动用户组(start group).初始化(Initialize).启动虚 ...
- T60
The smooth contour of the sculpture is wonderful.Her commitment to a great cause degenerated from a ...
- TF-IFD算法及python实现关键字提取
TF-IDF算法: TF:词频(Term Frequency),即在分词后,某一个词在文档中出现的频率. IDF:逆文档频率(Inverse Document Frequency).在词频的基础上给每 ...
- dsu on tree(无讲解)
CF741D. Arpa's letter-marked tree and Mehrdad's Dokhtar-kosh paths 分析: 最多有一个字符出现奇数次 维护某个状态下深度的最大值,注意 ...