随笔分类 - 递推、递归、分治
摘要:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2066&cid=1158View Code #include #include long long num; int main() { int n,k,T,i ; w...
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2064&cid=1158View Code #include<stdio.h> long long f(int n) { if(n==0) return 1 ; else return 3*f(n-1); } int main() { int n, t ; scanf("%d", &t) ; while(t--) { scanf("%d", &n) ; printf("...
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2067&cid=1158View Code #include<stdio.h>#include<string.h>#define max(a, b) (a>b?a:b)struct node{ int len, a[1000] ;}dp[251] ;void add(node a, node b, node &c){ int i ; int len = max(a.len, b.len) ; for(i=1; i<=len; i++) c.a
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2065&cid=1158View Code #include<stdio.h>int main(){ int n, i ; int f[31] ; while(scanf("%d", &n)!=EOF) { if(n==-1) break ; f[0] = 1 ; f[2] = 3 ; for(i=4; i<=n; i=i+2) f[i] = 4*f[i-2] - f[i-4] ; ...
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2062&cid=1157法一:用dp[i][0]、dp[i][1]表示递推到第i位时为0以及非0的情况种数进行dp。View Code #include<stdio.h>int main(){ long long dp[20][2] ; int n, k ; while(scanf("%d %d", &n, &k)!=EOF) { dp[1][1] = k-1 ; dp[1][0] = 0 ; for(int i=2; i<=n..
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1150View Code 1 #include<iostream> 2 #include<cmath> 3 using namespace std ; 4 int a[2000000], b[2000000] ; 5 int n ; 6 int main() 7 { 8 int i, j, t, num, q ; 9 cin>>n ;10 t = sqrt(n) ;11 num = 0 ;12 for(i=2
阅读全文
摘要:题目描述话说天下大势,分久必合,合久必分。。。却道那魏蜀吴三国鼎力之时,多少英雄豪杰以热血谱写那千古之绝唱。古人诚不我欺,确是应了那句“一将功成万骨枯”。是夜,明月高悬。诸葛丞相轻摇羽扇,一脸愁苦。原来是日前蜀国战事吃紧,丞相彻夜未眠,奋笔急书,于每个烽火台写下安排书信。可想,这战事多变,丞相运筹 帷幄,给诸多烽火台定下不同计策,却也实属不易。谁成想这送信小厮竟投靠曹操,给诸葛丞相暗中使坏。这小厮将每封书信都投错了烽火台,居然没有一封是对的。不多时小厮便被抓住,前后之事却也明朗。这可急坏了诸葛丞相,这书信传错,势必会让蜀军自乱阵脚,不攻自破啊! 诸葛丞相现在想知道被这小厮一乱,这书信传错共有多
阅读全文
摘要:题目描述人称“AC女之杀手”的超级偶像LELE最近忽然玩起了深沉,这可急坏了众多“Cole”(LELE的粉丝,即"可乐"),经过多方打探,某资深Cole终于知道了原因,原来,LELE最近研究起了著名的RPG难题: 有排成一行的n个方格,用红(Red)、粉(Pink)、绿(Green)三色涂每个格子,每格涂一色,要求任何相邻的方格不能同色,且首尾两格也不同色.求全部的满足要求的涂法。以上就是著名的RPG难题。如果你是Cole,我想你一定会想尽办法帮助LELE解决这个问题的;如果不是,看在众多漂亮的痛不欲生的Cole女的面子上,你也不会袖手旁观吧?输入输入数据包含多个测试实例,
阅读全文
摘要:题目描述A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Given A, B, and n, you are to calculate the value of f(n).输入The input consists of multiple test cases. Each test case contains 3 integers A, B and n on a single line (1 <= A, B <= 1000,
阅读全文

浙公网安备 33010602011771号