Matches

UVA - 11375

题意: 给你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的更多相关文章

  1. keil MDK error: L6236E: No section matches selector - no section 错误

    今天板子刚到,新建的第一个工程就报错了. .\Objects\cse.sct(7): error: L6236E: No section matches selector - no section t ...

  2. 解决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 ...

  3. HDU5456 Matches Puzzle Game(DP)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5456 Description As an exciting puzzle game for ...

  4. Matches正则使用提取内容

    用VS新建WinForm程序,窗体上是三个文本框和一个按钮.可以自己构造正则表达式,自己修改匹配内容 正则表达是要提取的部分为hewenqitext 代码如下: using System; using ...

  5. js之 matches (可以取代jq的 delegate 方法)

    问题:请给#wrap 下面的子元素添加点击事件! <div id="wrap"> <a class="btn" href="http ...

  6. Owin SelfHost Asp.net WebApi 遇到 No type was found that matches the controller named 'ControllerName' 异常的解决方案

    问题背景:在使用普通的SelfHost时,调用其它工程的dll(其实就是把WebApi写到一个单独的工程方便管理),通过加载其他工程的dll然后再访问webapi是没有问题的. 但是在使用Owin S ...

  7. uva 11357 Matches

    // uva 11357 Matches // // 题目大意: // // 给你n个火柴,用这n个火柴能表示的非负数有多少个,不能含有前导零 // // 解题思路: // // f[i] 表示正好用 ...

  8. android中出现Error retrieving parent for item: No resource found that matches the Theme.AppCompat.Light

    styles.xml中<style name="AppBaseTheme" parent="Theme.AppCompat.Light">提示如下错 ...

  9. 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 ...

随机推荐

  1. T_CODE I18N

    关于T-CODE I18N 最近由于看到很多人遇到SMARTFORMS不能拖拽字段的问题,这个的解决方案 I18N:解决SMARTFORMS的不能从Field name 那边直接把变量拖入右边编辑框 ...

  2. html--<meta>设置缓存

    html头文件设置常用之<meta>设置缓存   <meta http-equiv="pragma" content="no-cache"&g ...

  3. WPF区时浏览小程序

    在深圳已经工作了一个月了,之前做WinForm的,现在做WPF,每天加班到晚上10点,比之前累.学习新技术也是有个过程的,我就从基础的语法和 界面布局做起.这是我仿着做一个小软件. 效果图赏析 在原基 ...

  4. 20145239 《Java程序设计》实验三 实验报告

    详见我的parter20145224的博客:http://www.cnblogs.com/20145224kevs/p/5428892.html 感想:这次的实验看似容易,但很多点都需要注意,比如开源 ...

  5. UVA10294 Arif in Dhaka (First Love Part 2) —— 置换、poyla定理

    题目链接:https://vjudge.net/problem/UVA-10294 题解: 白书P146~147. 为什么旋转i个间距,就有gcd(i,n)个循环,且每个循环有n/gcd(i,n)个元 ...

  6. Spring Boot2.0之 整合JDBC

    很入门的知识,大家了解下就OK maven配置文件pom: spring: datasource: url: jdbc:mysql://localhost:3306/test username: ro ...

  7. html中css的三种样式

    在html中定义CSS样式的方法有三种,新建CSS文件 使用link 关联 这种是最常用的外部引用样式,第二种讲样式写在 head 头部里面 这种是页面样式 ,第三中样式直接写在行内  style里面 ...

  8. L95

    The children squealed with delight when they saw the puppy.The signal will be converted into digital ...

  9. 系列文章--突袭HTML5

    学习新的网站构建技术:基于HTML5,但不限于HTML5.   突袭HTML5之Javascript API扩展5 - 其他扩展   突袭HTML5之Javascript API扩展4 - 拖拽   ...

  10. dubbo的防痴呆设计

    项目中也经常会遇到各种因为配置而引入的问题,很多技术支持解决不掉就找开发,结果发现大部分还是配置错误或网络不通等.如果在设计之初就能考虑到并针对这些问题做出应对设计,甚至给出异常的解决方案,确实可以减 ...