11 2013 档案

hdu 3709 Balanced Number
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3709数位dp,练模板好题。。题目要求求出[x, y] 范围内的平衡数,平衡数定义为:以数中某个位为轴心,两边的数的偏移量为矩,数位权重,使得整个数平衡。当然,首先可以简化一下条件~,设Kp为以p为支点的平衡度;则 Kp = sum(di*(i-p)); 故△Kp = K(p+1) - Kp = -sum(di);记 ps = K0 (以0为支点的平衡度), s =sum(di);所以条件存在Kp == 0等价为 s|ps. 1 #include 2 #include 3 #include 4 #in... 阅读全文

posted @ 2013-11-16 15:36 KimKyeYu 阅读(163) 评论(0) 推荐(0)

数位dp 模版
摘要:1 int dfs(int i, int s, bool e) {2 if (i == -1) return s == target_s;3 if (!e && ~dp[i][s]) return dp[i][s];4 int res = 0;5 int u = e ? num[i] : 9;6 for (int d = first ? 1 : 0; d <= u; ++d)7 res += dfs(i-1, new_s(s, d), e&&d == u);8 return e ? res : dp[i][s] = res;9 }Vi... 阅读全文

posted @ 2013-11-07 20:04 KimKyeYu 阅读(357) 评论(0) 推荐(0)

导航