所以,如果我有一个定向非循环图,其中每个边的成本为0或大于0,如果它大于0它将具有负重量(所以你可以用它5美元它将缩短你的方式例如-20).
我知道我们可以在DAG中轻松找到最短/最便宜的方式,但如果我们的资金有限呢?
想象一下下一个情况:

我们有8个钱.算法会找到最短路径-10 + -3 = -13,但它会花费12但我们只有8个钱,所以它不是一个选项.理想的路径是-10 + 0,只需7美元.有没有一种算法可以用来解决这个问题?
from Crypto.Cipher import AES
import hashlib
def encryptString(plaintext, key):
# Encryption#
plaintext = Padding.pad(plaintext, AES.block_size);
iv = get_random_bytes(AES.block_size)
print('How many:' , sys.getsizeof(key));
cipher = AES.new(key, AES.MODE_CBC, iv)
ciphertext = cipher.encrypt(plaintext);
return (iv + ciphertext).hex();
def decryptString(ciphertextHex, key):
ciphertext = binascii.unhexlify(ciphertextHex)
iv = ciphertext[:AES.block_size]
ciphertext = ciphertext[AES.block_size:]
cipher = AES.new(key, AES.MODE_CBC, iv)
plaintext = cipher.decrypt(ciphertext)
plaintext = Padding.unpad(plaintext, AES.block_size)
return plaintext.decode('utf-8');
Run Code Online (Sandbox Code Playgroud)
我创建了一个 AES 加密/解密包装器。它与示例键一起使用,例如:
键 = b'0123456789abcdef0123456789abcdef'
但是,如果我生成这样的随机 AES 密钥(来自字符串)
def convertKey(self,key):
return hashlib.sha256(key.encode()).digest();
Run Code Online (Sandbox Code Playgroud)
然后它返回这个错误:
文件 "C:\Python36\lib\site-packages\Crypto\Util\Padding.py", line 93, in unpad …