【DP】 HDOJ 5230 ZCC loves hacking
来源:互联网 发布:小知运营助手下载 编辑:程序博客网 时间:2024/06/06 10:43
dp[i][j] 代表用了i个数,组成j的方案数,那么dp[i][j]可以由dp[i-1][j-i]递推而来,相当于前面i-1个数加1,最后加个1,也可以由dp[i][j-i]递推而来,相当于i个数每个数加1.。。
#include <iostream>#include <queue>#include <stack>#include <map>#include <set>#include <bitset>#include <cstdio>#include <algorithm>#include <cstring>#include <climits>#include <cstdlib>#include <cmath>#include <time.h>#define maxn 100005#define maxm 40005#define eps 1e-12#define mod 998244353#define INF 0x3f3f3f3f#define PI (acos(-1.0))#define lowbit(x) (x&(-x))#define mp make_pair//#define ls o<<1//#define rs o<<1 | 1//#define lson o<<1, L, mid //#define rson o<<1 | 1, mid+1, R//#pragma comment(linker, "/STACK:102400000,102400000")#define pii pair<int, int> typedef long long LL;typedef unsigned long long ULL;//typedef int LL;using namespace std;LL qpow(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base;base=base*base;b/=2;}return res;}LL powmod(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}// headLL res[maxn];LL dp[2][maxn];void init(){int now = 0, pre;dp[now][0] = 1;for(int i = 1; i <= 450; i++) {now = now ^ 1;pre = now ^ 1;for(int j = 0; j < maxn; j++) res[j] = (res[j] + dp[pre][j]) % mod;for(int j = 0; j < i; j++) dp[now][j] = 0;for(int j = i; j < maxn; j++) dp[now][j] = (dp[pre][j - i] + dp[now][j - i]) % mod;}for(int i = 1; i < maxn; i++) res[i] = (res[i] + res[i-1]) % mod;}void work(){int c, l, r, n;scanf("%d%d%d%d", &n, &c, &l, &r);l -= c, r -= c;LL ans = res[r];if(l) ans = ((ans - res[l-1]) % mod + mod) % mod;printf("%lld\n", ans);}int main(){int _;init();scanf("%d", &_);while(_--) work();return 0;}
0 0
- 【DP】 HDOJ 5230 ZCC loves hacking
- hdoj 5230 ZCC loves hacking
- HDU 5230 ZCC loves hacking(DP)
- hdu 5230 ZCC loves hacking
- HDU 5230 ZCC loves hacking
- hdu 5230 ZCC loves hacking
- HDU 5230 ZCC loves hacking DP(拆分数,加数不同)
- hdu5230 ZCC loves hacking
- hdu 5230 ZCC loves hacking(BestCoder Round #41)
- hdu 5230 ZCC loves hacking && BestCoder Round #41 1003
- HDOJ 4882 ZCC Loves Codefires
- HDOJ 4876 ZCC loves cards
- HDOJ 5229 ZCC loves strings
- hdu 5230 ZCC loves hacking(整数拆分的变形+前缀和)
- [HDOJ 4879] ZCC loves march [模拟+数据结构]
- [HDOJ 4876] ZCC loves cards [搜索]
- HDOJ 4876 ZCC loves cards(搜索)
- hdoj 4882 ZCC Loves Codefires 【贪心】
- 滚动条控件Scroll Bar(VS2010/MFC)
- C#日积月累之选择结构
- (1536)HDU
- Android中导入工程出现Project has no default.properties file! Edit the project properties to set one.的解决方法
- Matlab画函数图上机练习
- 【DP】 HDOJ 5230 ZCC loves hacking
- 《C陷阱与缺陷》阅读笔记1
- 观察者模式的应用场景及实现方式
- [刷题]Backpack
- ubuntu查看占用某端口的程序
- RelativeLayout(相对布局)
- 首先编程是什么
- 黑马程序员——Java基础-异常
- 操作系统学习(一) 进程