ACM: 有难度的深搜题 poj 3373
来源:互联网 发布:深圳阿里云大厦 编辑:程序博客网 时间:2024/06/16 09:28
Description
Given two positive integers n and k, you areasked to generate a new integer, say m, by changing some(maybe none) digits of n, such that the followingproperties holds:
- m contains no leading zeros and has the same length asn (We consider zero itself a one-digit integerwithout leading zeros.)
- m is divisible by k
- among all numbers satisfying properties 1 and 2, mwould be the one with least number of digits different fromn
- among all numbers satisfying properties 1, 2 and 3, mwould be the smallest one
Input
There are multiple test cases for the input. Each test caseconsists of two lines, which containsn(1≤n≤10100) andk(1≤k≤104, k≤n) foreach line. Both n and k will not contain leadingzeros.
Output
Output one line for each test case containing the desired numberm.
Sample Input
2
2
619103
3219
Sample Output
2
119103
题意: 现在给你两个数n , k. 要求一个新的数m.
解题思路:
代码:
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
#define MAX 110
int k, len;
char str[MAX];
int num[MAX], test[MAX];
int for_mod[MAX][10];
int remember[MAX][10010];
void init()
{
}
bool dfs(int left,int index,int mod)
{