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. Web框架和Django基础

    核心知识点 1.web应用类似于一个socket客户端,用来接收请求 2.HTTP:规定了客户端和服务器之间的通信格式. 3.一个HTTP包含两部分,header和body,body是可选,\r\n分 ...

  2. linux撤销命令

    u撤销上一步操作 ctrl+r恢复上一步被撤销的操作

  3. [2017-11-21]Abp系列——T4应用:权限树定义

    本系列目录:Abp介绍和经验分享-目录 今天介绍下,如何使用T4根据json文件自动生成权限定义. 先看成果 成果是: 要新增一个权限定义时,打开Json文件,找到目标节点,加个权限定义: 生成下Co ...

  4. HDU - 2102 A计划 【BFS】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2102 思路 题目有两个坑点 0.Output 说 能在T时刻 找到公主 就输出 YES 但实际上 只要 ...

  5. 复制一个带random指针的链表

    一个单链表,其中除了next指针外,还有一个random指针,指向链表中的任意某个元素.如何复制这样一个链表呢? 通过next来复制一条链是很容易的,问题的难点在于如何恰当地设置新链表中的random ...

  6. 嵌入式选择与L1正则化

    http://blog.csdn.net/irene_loong/article/details/73741521

  7. BZOJ 1202 [HNOI2005]狡猾的商人:并查集(维护距离)

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1202 题意: 有一个账本,记录了n个月的盈亏. 每个月的数值:正为盈,负为亏. 你知道m个 ...

  8. 最近火狐浏览器 总是“插件 adobe flash 已崩溃”

    原因和解决方案:在地址栏中输入:about:addons>在如下地方发现firefox已经在警告该插件的安全性了>选择“总不激活”

  9. Java_HTTP_01_HttpClient

    一. 二.参考文档 1. HttpClient官方文档 HttpClient官方文档中文翻译 1.HttpClient 4 实现文件下载 2.httpclient 上传文件.下载文件 3.httpcl ...

  10. (转)C++经典面试题(最全,面中率最高)

    1.new.delete.malloc.free关系 delete会调用对象的析构函数,和new对应free只会释放内存,new调用构造函数.malloc与free是C++/C语言的标准库函数,new ...