HDU1250 高精度斐波那契数列

Machine Schedule

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7632    Accepted Submission(s):
3816

Problem Description

As we all know, machine scheduling is a very classical
problem in computer science and has been studied for a very long history.
Scheduling problems differ widely in the nature of the constraints that must be
satisfied and the type of schedule desired. Here we consider a 2-machine
scheduling problem.

There are two machines A and B. Machine A has n kinds
of working modes, which is called mode_0, mode_1, …, mode_n-1, likewise machine
B has m kinds of working modes, mode_0, mode_1, … , mode_m-1. At the beginning
they are both work at mode_0.

For k jobs given, each of them can be
processed in either one of the two machines in particular mode. For example, job
0 can either be processed in machine A at mode_3 or in machine B at mode_4, job
1 can either be processed in machine A at mode_2 or in machine B at mode_4, and
so on. Thus, for job i, the constraint can be represent as a triple (i, x, y),
which means it can be processed either in machine A at mode_x, or in machine B
at mode_y.

Obviously, to accomplish all the jobs, we need to change the
machine‘s working mode from time to time, but unfortunately, the machine‘s
working mode can only be changed by restarting it manually. By changing the
sequence of the jobs and assigning each job to a suitable machine, please write
a program to minimize the times of restarting machines.

Input

The input file for this program consists of several
configurations. The first line of one configuration contains three positive
integers: n, m (n, m < 100) and k (k < 1000). The following k lines give
the constrains of the k jobs, each line is a triple: i, x, y.

The input
will be terminated by a line containing a single zero.

Output

The output should be one integer per line, which means
the minimal times of restarting machine.

Sample Input

5 5 10
0 1 1
1 1 2
2 1 3
3 1 4
4 2 1
5 2 2
6 2 3
7 2 4
8 3 3
9 4 3
0

Sample Output

3

Source

Asia
2002, Beijing (Mainland China)

Recommend

Ignatius.L   |   We have carefully selected several
similar problems for you:  1068 1151 1281 1507 1528

#include <iostream>
#include <stdio.h>
using namespace std;
int a[10000][260]={0};
int main()
{
    int i,j,n;
    a[1][0]=1;
    a[2][0]=1;
    a[3][0]=1;
    a[4][0]=1;
    for(i=5;i<10000;i++)
    {
        for(j=0;j<260;j++)
        {
            a[i][j]+=a[i-1][j]+a[i-2][j]+a[i-3][j]+a[i-4][j];
            a[i][j+1]+=a[i][j]/100000000;
            a[i][j]=a[i][j]%100000000;
        }
    }
    while(cin>>n)
    {
        for(j=259;j>=0;j--)
        if(a[n][j]!=0)
        break;
        cout<<a[n][j];
        for(j=j-1;j>=0;j--)
        printf("%08d",a[n][j]); //不能直接cout 数大的时候是错的 因为可能会输出七位 正常应该输出八位的 反正就是不对
        cout<<endl;
    }
    return 0;
}
时间: 2024-10-29 10:45:54

HDU1250 高精度斐波那契数列的相关文章

HDU1250大数+斐波那契数列

Description A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1. F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n - 1) + F(n-2) + F(n-3) + F(n-4) Your task is to take a number

HDU 1316 斐波那契数列+高精度

How Many Fibs? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4235    Accepted Submission(s): 1669 Problem Description Recall the definition of the Fibonacci numbers: f1 := 1 f2 := 2 fn := fn-1

斐波那契数列算法分析

背景: 假定你有一雄一雌一对刚出生的兔子,它们在长到一个月大小时开始交配,在第二月结束时,雌兔子产下另一对兔子,过了一个月后它们也开始繁殖,如此这般持续下去.每只雌兔在开始繁殖时每月都产下一对兔子,假定没有兔子死亡,在一年后总共会有多少对兔子? 在一月底,最初的一对兔子交配,但是还只有1对兔子:在二月底,雌兔产下一对兔子,共有2对兔子:在三月底,最老的雌兔产下第二对兔子,共有3对兔子:在四月底,最老的雌兔产下第三对兔子,两个月前生的雌兔产下一对兔子,共有5对兔子:……如此这般计算下去,兔子对数分

斐波那契数列——矩阵的幂求解

题目: 斐波那契数列的递推公式如下: F(0) = 0; F(1) = 1; F(n + 2) = F(n + 1) + F(n); 求数列的第N项的值对10000取余的结果.( 0<=n<= 10^16) 求解斐波那契数列,如果N比较小的情况下,可以直接打表求解,但是对于N很大的情况下,并不适用. 所以,有些人会想到高精度计算,但是,N达到10^5以上时,时间复杂度难以想象,每计算一个数,需要进行高精度加法.然而还有求解对10000的取余的值. 我们可以用矩阵的幂来求解.斐波那契数列的递推公

使用高精度计算斐波那契数列 c++

使用高精度计算斐波那契数列 非高精度 Code(Non-high accuracy) 这是不用高精度的代码 1 #include<bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 // freopen("斐波那契数列short_output.out","w",stdout); 6 unsigned long long x=1,y=1,t; 7 cout<<x<<end

用递归和非递归的方法输出斐波那契数列的第n个元素(C语言实现)

费波那契数列(意大利语:Successione di Fibonacci),又译为费波拿契数.斐波那契数列.费氏数列.黄金分割数列. 在数学上,费波那契数列是以递归的方法来定义: {\displaystyle F_{0}=0} {\displaystyle F_{1}=1} {\displaystyle F_{n}=F_{n-1}+F_{n-2}}(n≧2) 用文字来说,就是费波那契数列由0和1开始,之后的费波那契系数就是由之前的两数相加而得出.首几个费波那契系数是: 0, 1, 1, 2, 3

Fibonacci斐波拉契数列----------动态规划DP

n==10 20 30 40 50 46 体验一下,感受一下,运行时间 #include <stdio.h>int fib(int n){ if (n<=1)     return 1; else            return fib(n-1)+fib(n-2); }int main( ){ int n; scanf("%d",&n); printf("%d\n" ,fib(n) );} 先 n==10 20 30 40 50 46

《剑指Offer》题目——斐波拉契数列

题目描述:大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项.(n<=39) 题目分析:如果使用简单的递归,很容易造成栈溢出.采用递推的方式即可. 代码: public class Fibonacci { public static int fibonacci(int n){ int res[] = new int[2]; res[0]=1; res[1]=1; int temp = 0; if(n==0) return 0; if(n<=2) return res[

js算法集合(二) javascript实现斐波那契数列 (兔子数列) Javascript实现杨辉三角

js算法集合(二)  斐波那契数列.杨辉三角 ★ 上一次我跟大家分享一下做水仙花数的算法的思路,并对其扩展到自幂数的算法,这次,我们来对斐波那契数列和杨辉三角进行研究,来加深对Javascript的理解. 一.Javascript实现斐波那契数列 ①要用Javascript实现斐波那契数列,我们首先要了解什么是斐波那契数列:斐波那契数列(Fibonacci sequence),又称黄金分割数列.因数学家列昂纳多·斐波那契(Leonardoda Fibonacci)以兔子繁殖为例子而引入,故又称为