uva 11375 - Matches
来源:互联网 发布:怎么修改淘宝账户名 编辑:程序博客网 时间:2024/06/15 03:00
本题要用高精度,表示不会,上网找的高精度模板。。。
本题dp【i】表示用i个火柴所能组成的数的个数,
核心代码:
for(i=1;i<=9;i++)//0不能当第一个数,所以没赋初值dp[a[i]]=dp[a[i]]+one;//先赋初值,one是高精度的1.for(i=1;i<=2000;i++)for(j=0;j<=9;j++)dp[i+a[j]]=dp[i+a[j]]+dp[i];//递推求dp[6]=dp[6]+one;//单独将0这个数的情况 加上1.for(i=1;i<=2000;i++)dp[i]=dp[i]+dp[i-1];//由于火柴可以不全用,所以最后腰累加起来
#include <iostream> #include <stdio.h> #include <string.h> #include <math.h> #include <algorithm> #include <string> #include <vector> #include <list> using namespace std; const int maxn = 1000; struct bign //上网找的高精度的模板,目前水平还不会用c++编高精度。。{ int len, s[maxn]; //s是逆序存储 bign(){ memset(s, 0 , sizeof(s)); len = 1 ; } //构造函数 bign(int num) { *this = num ; } //初始化 bign(const char* num) { *this = num ; } string str() const { int i; string res = ""; for( i = 0 ; i < len ; i++ ) res = (char)( s[i] + '0' ) + res ; if (res == "") res = "0"; return res; } bign operator = (const char* num) { int i; len = strlen(num); for( i = 0 ; i < len ; i++ ) s[i] = num[len-i-1] - '0' ; return *this; } bign operator = (int num) { char s[maxn]; sprintf(s , "%d" , num); *this = s; return *this; } bign operator + (const bign& b) const { bign c; c.len = 0; int i, g; for( i = 0 , g = 0 ; g || i < ( len > b.len ? len : b.len ) ; i++ ) { int x = g ; if( i < len ) x += s[i] ; if( i < b.len ) x += b.s[i] ; c.s[c.len++] = x % 10 ; g = x / 10 ; } return c; } //比较的前提是两个数都没有前导零 bool operator < (const bign& b) const { if( len != b.len ) return len < b.len ; int i; for( i = len-1 ; i >= 0 ; i-- ) if( s[i] != b.s[i] ) return s[i] < b.s[i]; return false; } bool operator > (const bign& b) const { return b < *this; } bool operator <= (const bign& b) const { return !(b < *this); } bool operator >= (const bign& b) const { return !(*this < b); } bool operator != (const bign& b) const { return b < *this || *this < b; } bool operator == (const bign& b) const { return !(b < *this) || !(*this < b); } }; istream& operator >> (istream &in , bign& x) { string s; in >> s; x = s.c_str(); return in; } ostream& operator << (ostream &out , const bign& x) { out << x.str(); return out; } int n;bign dp[2020];int a[12]={6,2,5,5,4,5,6,3,7,6};int main(){int i,j;bign one=1;for(i=1;i<=9;i++)dp[a[i]]=dp[a[i]]+one;for(i=1;i<=2000;i++)for(j=0;j<=9;j++)dp[i+a[j]]=dp[i+a[j]]+dp[i];dp[6]=dp[6]+one;for(i=1;i<=2000;i++)dp[i]=dp[i]+dp[i-1];while(scanf("%d",&n)!=EOF)cout<<dp[n]<<endl;}
- Matches UVA 11375
- uva 11375 - Matches
- UVA 11375 - Matches
- UVA 11375 - Matches
- UVA - 11375 Matches
- UVa:11375 Matches
- UVa 11375 Matches
- UVa 11375 Matches
- Matches(uva 11375)
- UVa 11375 Matches (DP&高精度)
- uva 11375 - Matches(递推)
- UVA - 11375-Matches-dp+高精度
- Matches UVA
- UVA 11375 Matches(递推)
- UVA 11375 Matches (dp+高精度)【模板】
- UVA 11375 - Matches (数学——递推)
- Uva 11375 Matches 解题报告(递推+高精度)
- UVa 11375 - Matches (递推 JAVA 高精度)
- Android手机蓝牙实现多人即时聊天
- 实现页面图片防盗链
- C#的LINQ语句
- 杭电 HDU 2141 Can you find it
- 华硕拆机之后解决无法进入windows7但能进入linux系统的办法
- uva 11375 - Matches
- hadoop的伪分布安装
- Google Android 文档笔记-Training-Getting started [2]
- jave学习第一节代码
- 黑马程序员__一些比较重要的类
- 题目1527:首尾相连数组的最大子数组和-九度
- fread
- ssh 免密钥登陆
- 为什么需要Page Object?