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. OSGI简介(转)

    原文地址 目前,业内关于OSGI技术的学习资源或者技术文档还是很少的.我在某宝网搜索了一下“OSGI”的书籍,结果倒是有,但是种类少的可怜,而且几乎没有人购买.因为工作的原因我需要学习OSGI,所以我 ...

  2. Database: coursera assignment 1

    q.1: Find the titles of all movies directed by Steven Spielberg. select title from moviewhere direct ...

  3. Windows、Linux、Mac OSX编译jni动态库

    在不同平台下默认调用不同名字的动态库,在Windows平台调用name.dll,在Linux平台调用libname.so,在OSX下调用libname.jnilib.不同平台下的编译的方法也有些区别. ...

  4. ZOJ - 3430 Detect the Virus —— AC自动机、解码

    题目链接:https://vjudge.net/problem/ZOJ-3430 Detect the Virus Time Limit: 2 Seconds      Memory Limit: 6 ...

  5. Contiki学习资料

    一.官方网站 官网主页:http://contiki-os.org/ 资源和支持:http://contiki-os.org/support.html The Contiki Community: h ...

  6. BZOJ 1637 [Usaco2007 Mar]Balanced Lineup:前缀和 + 差分

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1637 题意: Farmer John 决定给他的奶牛们照一张合影,他让 N (1 ≤ N ...

  7. [原创]Java在线编辑word文档调用PageOffice实现并发控制

    1.功能介绍 PageOffice的并发控制功能用来解决多个用户在线编辑同一篇文档可能造成的互相覆盖修改结果的技术难题. B/S架构下用户访问都是并发的,也就是说经常会出现同时N个用户对一个服务器页面 ...

  8. ivew组件的使用

    iview的官网:https://www.iviewui.com/docs/guide/start 1.选择快速上手 2.安装 解压,cmd,cd进你解压后的文件,cnpm i 3.打包 npm ru ...

  9. 【Lintcode】096.Partition List

    题目: Given a linked list and a value x, partition it such that all nodes less than x come before node ...

  10. poj2279排队——杨氏矩阵与钩子公式(DP爆内存)

    题目:http://poj.org/problem?id=2279 书上的DP做法会爆内存,尝试写了一个,过了样例. 转载: 代码如下: #include<iostream> #inclu ...