【UVA】580-Critical Mass
依据递推公式计算,须要打表不然可能会超时。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<string>
#include<sstream>
#include<ctime>
using namespace std;
#define _PI acos(-1.0)
#define INF (1 << 10)
#define esp 1e-6
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pill;
/*===========================================
===========================================*/
#define MAXD 50
int m;
LL f[MAXD];
LL g[MAXD];
LL _g(int _n){
LL ans = (1 << _n) - f[_n];
return ans;
}
LL solve(int _n){
if(_n < 3)
f[_n] = 0;
else{
LL ans = (1 << (_n - 3));
for(int i = 2 ; i <= _n - 2 ; i++){
ans += g[i - 2] * (1 << (_n - i - 2));
}
f[_n] = ans;
}
g[_n] = _g(_n);
return f[_n];
}
int main(){
memset(f,-1,sizeof(f));
LL ans ;
for(int i = 0 ; i <= 30 ; i++)
ans = solve(i);
while(scanf("%d",&m) && m){
printf("%lld\n",f[m]);
}
return 0;
}
【UVA】580-Critical Mass的更多相关文章
- CJOJ 1070 【Uva】嵌套矩形(动态规划 图论)
CJOJ 1070 [Uva]嵌套矩形(动态规划 图论) Description 有 n 个矩形,每个矩形可以用两个整数 a, b 描述,表示它的长和宽.矩形 X(a, b) 可以嵌套在矩形 Y(c, ...
- CJOJ 1071 【Uva】硬币问题(动态规划)
CJOJ 1071 [Uva]硬币问题(动态规划) Description 有n种硬币,面值分别为v1, v2, ..., vn,每种都有无限多.给定非负整数S,可以选用多少个硬币,使得面值之和恰好为 ...
- 题解 【Uva】硬币问题
[Uva]硬币问题 Description 有n种硬币,面值分别为v1, v2, ..., vn,每种都有无限多.给定非负整数S,可以选用多少个硬币,使得面值之和恰好为S?输出硬币数目的最小值和最大值 ...
- UVa 580 - Critical Mass(递推)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 580 Critical Mass
https://vjudge.net/problem/UVA-580 题意:一堆U和L,用n个排成一排,问至少有3个U放在一起的方案数 f[i] 表示 至少有3个U放在一起的方案数 g[i] 表示没有 ...
- UVA 580 Critical Mass (两次dp)
题意:一个字符串有n个位置每个位置只可能是L或者U,问你在所有可能出现的字符串中最少出现一次三个U连在一起的字符串的个数 题解:首先从左向右枚举每个位置i,保证i,i+1,i+2是U,并且i+2(不包 ...
- 【UVa】11270 Tiling Dominoes
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- 【UVA】【10828】随机程序
数学期望/高斯消元/马尔可夫过程 刘汝佳老师白书上的例题- -b 本体不满足拓扑关系,但马尔可夫过程是可以高斯消元解的…… 用「高斯·约当消元」更方便! //UVA 10828 #include< ...
- 【UVA】【11762】Race to 1(得到1)
数学期望/马尔可夫过程 DP/记忆化搜索 刘汝佳老师白书上的例题…… //UVA 11762 #include<vector> #include<cstdio> #includ ...
随机推荐
- [LeetCode179]Largest Number
题目: Given a list of non negative integers, arrange them such that they form the largest number. For ...
- 查看oracle数据库的连接数以及用户
查看oracle数据库的连接数以及用户 11.查询oracle的连接数2select count(*) from v$session;32.查询oracle的并发连接数4select count(*) ...
- IDEA内存异常问题
设置工程运行Server VM属性 VM options: -Xms258m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=256m 如图 :
- Demo of Python "Map Reduce Filter"
Here I share with you a demo for python map, reduce and filter functional programming thatowned by m ...
- 怎么将Emeditor设置成网页查看源代码的默认编译器
1.打开emditor: 2.在菜单栏中找到工具---->自定义,打开自定义窗口: 3.快捷方式--->更多快捷方式 5.选中“在internet explorer中通过emeditor查 ...
- C# 读取IE缓存文件(1)
using System; using System.Runtime.InteropServices; namespace Common { public class IECache { [DllIm ...
- TextWatcher原因activity内存泄漏问题
TextWatcher原因activity内存泄漏. EditText配置addTextChangedListener该接口,至onDestroy电话里removeTextChangedListene ...
- epoll演示样本
server参考是别人的代码 #include <stdio.h> #include <stdlib.h> #include <errno.h> #include ...
- GoldenGate组态(四)它veridata组态
GoldenGate组态(四)它veridata组态 环境: Item Source System Target System Platform Red Hat Enterprise Linux Se ...
- NET MVC权限验证
ASP.NET MVC权限验证 封装类 写该权限类主要目地 为了让权限配置更加的灵活,可以根据SQL.json.或者XML的方式来动态进行页面的访问控制,以及没有权限的相关跳转. 使用步骤 1.要建一 ...