Given an increasing sequence of integers a1, a2, a3, . . . , ak, the E-transform produces a sequence of the
same length, b1, b2, b3, . . . , bk such that
• b1 = a1
• for j > 1, bj is the only integer aj−1 < bj ≤ aj, which is divisible byaj − aj−1.
For example, from S = 0,1,4,9,16,25,36,49 one gets E(S) = 0,1,3,5,14,18,33,39.
A sequence S such that E(S) = S is called an eigensequence.
For instance, S = 2,3,4,6,8,12,16,18,20 is an eigensequence.
Given integers a1 and an, how many eigensequences (of any length) start with a1 and end with an?
Input
Input has many data lines, followed by a terminating line. Each line has two integers, a1 and an. If
a1 < n, it’s a data line. Otherwise it’s a terminating line that should not be processed. On each line,
0 ≤ a1 ≤ an ≤ 44. This guarantees that each output fits into 32 bit integer.
Output
For each data line, print a line with a1, an, and x, where x is the number of eigensequences (of any
length) that start with a1 and end with an.
Sample Input
0 3
5 7
2 8
0 0
Sample Output
0 3 3
5 7 1
2 8 12

题意:给你一个递增序列的第一位a1,最后一位an,求有多少个序列满足:以a1为首,an为尾

1、B(1) = A(1)

2、后面每项满足,A(j-1) < B(j) ≤ A(j), 且bj能整除A(j) - A(j-1)。

题解:看题目由于给的a1,an都很小我们设定dp[i][j]以第i位以结尾的方案数,

那么  对于满足上述条件就能转移

//meek
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include<map>
#include<queue>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair const int N=;
const ll INF = 1ll<<;
const int inf = ;
const int MOD= ; ll dp[N][N],vis[N][N];
int a1,an;
ll dfs(int now,int sum) {
if(vis[now][sum]) return dp[now][sum];
vis[now][sum] = ;
ll& ret = dp[now][sum];
ret = ;
if(sum == an) return ret = ;
for(int i = sum+; i <= an; i++) {
if(i%(i-sum)) continue;
ret += dfs(now+,i);
}
return ret;
}
int main() {
while(~scanf("%d%d",&a1,&an)) {
if(a1 == && an == ) break;
mem(vis);
printf("%d %d %lld\n",a1,an,dfs(a1,a1));
}
return ;
}

代码

UVA 11133 - Eigensequence DP的更多相关文章

  1. UVA.10192 Vacation (DP LCS)

    UVA.10192 Vacation (DP LCS) 题意分析 某人要指定旅游路线,父母分别给出了一系列城市的旅游顺序,求满足父母建议的最大的城市数量是多少. 对于父母的建议分别作为2个子串,对其做 ...

  2. UVA.10130 SuperSale (DP 01背包)

    UVA.10130 SuperSale (DP 01背包) 题意分析 现在有一家人去超市购物.每个人都有所能携带的重量上限.超市中的每个商品有其相应的价值和重量,并且有规定,每人每种商品最多购买一个. ...

  3. BZOJ 1260&UVa 4394 区间DP

    题意: 给一段字符串成段染色,问染成目标串最少次数. SOL: 区间DP... DP[i][j]表示从i染到j最小代价 转移:dp[i][j]=min(dp[i][j],dp[i+1][k]+dp[k ...

  4. UVa 10029 hash + dp

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  5. uva 10154 贪心+dp

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  6. UVA 1358 - Generator(dp+高斯消元+KMP)

    UVA 1358 - Generator option=com_onlinejudge&Itemid=8&page=show_problem&category=524& ...

  7. uva 1534 - Taekwondo(dp+馋)

    题目连接:uva 1534 - Taekwondo 题目大意:有两组什么东西,题目背景有点忘记了,就是给出两组数,两组个数分别为n,m,要求找出min(n,m)对数.每一个数最多最多选一次,使得这mi ...

  8. uva 10118(DP)

    UVA 10118 题意: 有4堆糖果,每堆有n(最多40)个,有一个篮子,最多装5个糖果,我们每次只能从某一堆糖果里拿出一个糖果, 如果篮子里有两个相同的糖果,那么就可以把这两个(一对)糖果放进自己 ...

  9. UVA 1626 区间dp、打印路径

    uva 紫书例题,这个区间dp最容易错的应该是(S)这种匹配情况,如果不是题目中给了提示我就忽略了,只想着左右分割忘记了这种特殊的例子. dp[i][j]=MIN{dp[i+1][j-1] | if( ...

随机推荐

  1. hdu 2275 Kiki & Little Kiki 1

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2275 题意:n个操作 Push 入容器 Pop弹出一个 满足<=该数的最大的数(若没有输出No ...

  2. Android 解决图片大量下载:软引用必须懂4点

    1.对象的强.软.弱和虚引用为了能更加灵活控制对象的生命周期,需要知道对象引用的4中级别,由高到低依次为 :强引用.软引用.弱引用和虚引用 备注: 这四种的区别: ⑴强引用(StrongReferen ...

  3. 1.Knockout.Js(简介)

    前言 最近一段时间在网上经常看到关于Knockout.js文章,于是自己就到官网看了下,不过是英文的,自己果断搞不来,借用google翻译了一下.然后刚刚发现在建立asp.net mvc4.0的应用程 ...

  4. 重装win7系统的方法

    1.当电脑可以运行的情况下重装系统: 用傻瓜似的重装系统就可以了,这个简单,不在累赘. 2.当电脑打不看的情况下: 2.1 用光盘安装系统,这个有好多教程,不在累赘. 2.2 用U盘安装方法: 2.2 ...

  5. shell 简介

    shell 简介 shell既是一种命令语言,也是一种程序设计语言.作为命令语言,它交互式地解析和执行用户输入的命令:作为程序设计语言,他定义了各种变量和参数,并提供了许多的高级语言才具有的控制结构, ...

  6. C++中的抽象类及纯虚函数的实现与否

    1.含有纯虚函数的叫抽象类 2.抽象类(一般是基类)中的纯虚函数无论函数体实现与否,都没有关系,系统会自动忽略 3.继承自抽象类的子类,必须要实现父类的纯虚函数才可以实例化对象 4.抽象类不允许实例化 ...

  7. Linux学习之路--启动VNC服务

    我的Linux是Fedora 13,安装方法如下: 1.打开终端,执行 # yum install -y tigervnc tigervnc-server 2.编辑/etc/sysconfi/vncs ...

  8. HIbernate小结

    one-to-many和cascade不是关联很紧的东西. one-to-many后最明显的改变是数据库约束的产生. cascade是指,比如你设置cacade为"save-update&q ...

  9. 三、freemarker数据、模版指令

    数据类型 1.         直接指定值(字符串.数值.布尔值.集合.Map对象) 2.         字符串:直接指定字符串使用单引号.双引号,字符中间可以使用转义符“\”,如果字符内有大量特殊 ...

  10. c语言学习strcopy

    自己写了一个字符串复制函数: #include<stdio.h> #include<assert.h> char *mystrcpy(char *des,char *ser) ...