UVA 11361 - Investigating Div-Sum Property(数位DP)

题目链接:11361 - Investigating Div-Sum Property

白书上的例题,不过没有代码,正好前几天写了一题数位DP的题目,这题也就相对轻松了。
dp[i][x][y]表示加到第i位,数字 % k,数位和 % k的组合情况数,那么现在要添加一个0 - 9的数字上去状态转移为
dp[i + 1][(x * 10 + num) % k][(y + num) % k],计算总和后,由于数字本身不能超过最大值,所以最后还要添加上恰好前几位都为最大值的情况。然后最后在判断一下该数字本身符不符合条件。 注意边界0的时候答案为1.
代码:
#include <stdio.h>
#include <string.h>

int t, a, b, k, f[15][105][105], n, d[15];

void tra(int num) {
	n = 0;
	while (num) {
		d[++n] = num % 10;
		num /= 10;
	}
	for (int i = 1; i <= n / 2; i++) {
		int t = d[i];
		d[i] = d[n + 1 - i];
		d[n + 1 - i] = t;
	}
}

int solve(int num) {
	if (num == 0) return 1;
	tra(num);
	memset(f, 0, sizeof(f));
	int x1 = 0, x2 = 0;
	for (int i = 1; i <= n; i++) {
		for (int x = 0; x < k; x++) {
			for (int y = 0; y < k; y++) {
				for (int j = 0; j <= 9; j++) {
					f[i][(x * 10 + j) % k][(y + j) % k] += f[i - 1][x][y];
				}
			}
		}
		for (int j = 0; j < d[i]; j++)
			f[i][(x1 * 10 + j) % k][(x2 + j) % k]++;
		x1 = (x1 * 10 + d[i]) % k;
		x2 = (x2 + d[i]) % k;
	}
	if (x1 == 0 && x2 == 0)
		f[n][0][0]++;
	return f[n][0][0];
}

int main() {
	scanf("%d", &t);
	while (t--) {
		scanf("%d%d%d", &a, &b, &k);
		if (k > 100) printf("0\n");
		else printf("%d\n", solve(b) - solve(a - 1));
	}
	return 0;
}


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Preface The introduction of the IBM Personal Computer in 1982 fostered a technology revolution that has changed the way the world does business. Prior to that historic milestone, several personal computers existed, e.g., Apple, TRS 80, but they were primarily used by individuals, schools, and small businesses. When computer main- frame giant, International Business Machines (IBM) entered the personal computer market in 1982, the event quickly captured the attention of corporations and gov- ernment agencies worldwide. Personal computers were no longer thought of as toys and almost overnight they were accepted as reliable business computers. Since their introduction, IBM PCs and compatible computers have evolved into powerful corporate network servers, desktop computers, and notebook computers. They have also migrated into millions of households, and their popularity exploded during the 1990s when the world discovered the Internet. The worldwide popularity of both personal computers and the Internet has been a mixed blessing. The immediate popularity of the IBM PC was not anticipated. The DOS operating system installed on the original personal computers back in 1982 was never intended for commercial use and therefore was not designed to be secure. In the interest of maintaining compatibility with the early versions of DOS, upgrades to the operating system could not adequately address security issues. As a result, most corporate desktop PCs and notebook computers lack adequate secu- rity. Millions of personal computers are used as tools to conduct financial transactions and to store trade secrets, sensitive personal medical data, and employment infor- mation. Many of these computers and more are also connected to the Internet to send and receive e-mail and to browse the wealth of information on the World Wide Web. The designers of the Internet never envisioned that it would become the hub of international commerce. As a result, security was not built into the original design of the Internet. The wide acceptance of the personal computer and the Internet has created some concerns for security that are just now being realized. The dramatic increase in computing speeds has added to the dilemma because such speeds aid hackers in breaking into systems. The inherent security problems associated with personal computers, tied to their popularity in the workplace, have fostered new corporate problems. Now internal audits involve the examination of computer records. Criminal investigations and civil investigations routinely involve computer evidence and such inquiries require new methods and tools for investigators and internal auditors alike. That is what this book is all about, and its coming has been long overdue. It deals with practical methods and techniques that have proven to be effective in law enforcement and ©2000 by CRC Press LLC military circles for years. Only recently has this type of information and tools been available to corporate auditors and investigators. Michael R. Anderson Mr. Anderson retired after 25 years of federal law enforcement service and is currently the president of New Technologies, Inc., a corporation that provides train- ing and develops specialized forensic tools for use in computer evidence processing. While employed by the federal government, he developed some of the original computer evidence training courses for the federal government and is currently a member of the faculty of the University of New Haven, Connecticut. He is also a co-founder of the International Association of Computer Investigative Specialists and is a training advisor to the National White Collar Crime Center. He can be reached via e-mail at [email protected] regarding computer evidence- and security review-related questions.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值