[DP] Codechef .Chef And Fibonacci Array
来源:互联网 发布:一本好书 知乎 编辑:程序博客网 时间:2024/05/22 00:43
chuansongmen
首先有一个
然后猜猜猜
发现每个数,最多加前两个数中的最小值,那么就猜不存在一种变换,使其中一个数大于100,写完DP后assert了一下,发现RE了…
那么就猜不大于150,就过了…
转移的时候去掉无效的转移常数就贼小
#include <cstdio>#include <iostream>#include <algorithm>#include <string>#include <cstring>#include <assert.h>using namespace std;const int N=160,P=1e9+7;int t,n,a[N],f[N][N][N];inline void add(int &x,int y){ if((x+=y)>=P) x-=P;}int main(){ scanf("%d",&t); while(t--){ memset(f,0,sizeof(f)); memset(a,0,sizeof(a)); scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); if(n==1){ printf("%d\n",1); continue; } f[2][a[2]][a[1]]=1; for(int i=2;i<=150;i++) for(int j=0;j<=150;j++) for(int k=0;k<=150;k++) if(f[i][j][k]) for(int s=0;s<=j && s<=k;s++){ assert(a[i+1]+s<=150); add(f[i+1][a[i+1]+s][j-s],f[i][j][k]); } printf("%d\n",f[100][0][0]); } return 0;}
阅读全文
0 0
- [DP] Codechef .Chef And Fibonacci Array
- codechef Chef and Rainbow Array - 2
- CodeChef Chef and Segments
- codechef Chef and sequence
- codechef Chef and Swaps
- Codechef Chef and Reversing
- Codechef Chef and Frogs
- Codechef Chef and Churu
- 【CodeChef】 Chef and Stones
- 【CodeChef】Chef and Interview
- codechef Chef and Churu
- 【codechef】Chef and Bracket-Pairs (分层dp)
- 【codechef】Chef and the Cards(dp,推论)
- codechef Chef and easy problem
- codechef Chef and Left-Right
- codechef-Chef and Prime Divisors
- CodeChef Chef and Strange Operations
- Chef and Graph Queries (codechef)
- Linux虚拟地址空间布局以及进程栈和线程栈总结
- python的购物车实例
- ucenter 的同步登录和退出
- Python爬虫——爬取中国高校排名前100名并写入MySQL
- 详解spring 每个jar的作用
- [DP] Codechef .Chef And Fibonacci Array
- react-native 史上最搓的登陆注册
- 【ZZULIOJ 2179:】 紧急营救 【spfa +枚举】
- 数据结构实验之排序六:希尔排序
- node异步流程控制
- Node.js 安装
- JAVA的Collections类中shuffle的用法
- 加快IDEA中MAVEN的pom文件下载资源的速度
- 树状数组(二维)